[Solved] How to save background color in cookie through button click?

You can do it like this: window.addEventListener(‘DOMContentLoaded’, function() { var cookieValue = getCookie(‘backgroundColor’), btns = document.querySelectorAll(‘.color-btn’); if (cookieValue) { setBackgroundColor(cookieValue); } Array.from(btns).forEach(function(btn) { btn.addEventListener(‘click’, function() { var color = this.getAttribute(‘data-color’); setBackgroundColor(color); }); }); }); function setBackgroundColor(color) { document.body.style.backgroundColor = color; setCookie(‘backgroundColor’, color); } function getCookie(name) { var cookies = document.cookie.split(‘;’), cookie = cookies.find(function(str) { return … Read more

[Solved] How do I have two javascripts to work on a page? [closed]

You are including 2 copies of jQuery. Don’t do that; it is likely your problem. In the first block, you are including 3 scripts, the first of which is jQuery: // from Google CDN <script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script> In your second block you are again including jQuery: // From local <script type=”text/javascript” src=”https://stackoverflow.com/questions/18769142/scripts/jquery.js”></script> You should only … Read more

[Solved] how to display size on shape after scaled using fabric js?

function updateMeasures(evt) { var obj = evt.target; if (obj.type != ‘group’) { return; } var width = obj.getWidth(); var height = obj.getWidth(); obj._objects[1].text = width.toFixed(2) + ‘px’; obj._objects[1].scaleX= 1 / obj.scaleX; obj._objects[1].scaleY= 1 / obj.scaleY; obj._objects[2].text = height.toFixed(2) + ‘px’; obj._objects[2].scaleX= 1 / obj.scaleY; obj._objects[2].scaleY= 1 / obj.scaleX; } canvas = new fabric.Canvas(‘canvas’); var rect … Read more

[Solved] Html button who can load/fire multiple JS/button in each div

Determine a way to identify the button. For example, if your page looks like this: <header> … </header> <section id=”songs”> <button>…</button> <button>…</button> <button>…</button> </section> … then you could get a list of buttons with: var buttons = document.getElementById(“songs”).getElementsByTagName(“button”); Then loop through the buttons, and call button.click(). 1 solved Html button who can load/fire multiple JS/button … Read more

[Solved] How to find my link in an external domain name [closed]

You have to do that on server side e.g. with PHP PHP(checkDomain.php): <?php $string = file_get_contents(‘http://www.shaarzh.com’); //Get external content $reg = ‘/example.com/s’; //Search pattern if(preg_match($reg, $string)){ $array = array(‘response’ => ‘true’); }else{ $array = array(‘response’ => ‘false’); } echo json_encode( array(‘response’=>’false’) ); //Response ?> Now you can call the PHP-script with JavaScript. JavaScript(jQuery): $.ajax({ url: … Read more

[Solved] How can I Bold First two words bold in a paragraph Dynamically? [closed]

You can achieve this as below: <!DOCTYPE html> <html lang=”en”> <head> <script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js”></script> </head> <body> <p class=”boldTwoWord”>How can I Bold First two words bold in a paragraph Dynamically?</p> <br/> <p class=”boldTwoWord”>I am trying to bold first two words in the Paragraph what can i do ? for that</p> </body> <script type=”text/javascript”> var elms = $(“.boldTwoWord”); … Read more

[Solved] I want to close the website if the user answers yes [duplicate]

below script will only work in Firefox.if we enable the settings allow_scripts_to_close_windows. For that 1.Open FireFox 2.Enter about:config in Address bar 3.It will open a Config page of Firefox 4.Search allow_scripts_to_close_windows 5.It will show allow_scripts_to_close_windows.by default value will be false.To enable double click on the allow_scripts_to_close_windows row.It will change to true 6.Close Firefox Then execute … Read more

[Solved] Fade In and Out on Button Click

You only need to have the button click add the class membership, wait until the animation is complete and then remove the class. var div = document.querySelector(“.fade”); var btn = document.querySelector(“.fadeButton”); btn.addEventListener(“click”, function(){ div.classList.add(“elementToFadeInAndOut”); // Wait until the animation is over and then remove the class, so that // the next click can re-add it. … Read more

[Solved] Make an Image(s) appear after hovering over an tag(s)

I think the best idea is to use a data-[type] and compare it with an ID, class or other data-type. You can also do this with a class ofcourse. Here is a fiddle. And here is the jQuery code: $(“div#links > a”).hover( function() { var ID = $(this).data(“content”); $(“div#images”).children(“img#” + ID).fadeIn(“slow”); }, function() { var … Read more

[Solved] How to update an HTML table content without refreshing the page? [closed]

in html <tbody id=”table-body”> <?php include ‘tableBody.php’;?> </tbody> in your button function $.get(“tableBody.php”, function(data) { $(“#table-body”).html(data); }); When the button function is trigger, it will fire up the AJAX GET request to the tableBody.php, and then use its content to update the <tbody> with id table-body. 2 solved How to update an HTML table content … Read more

[Solved] How to add javascript to HTML?

There are two problems: You need to include a reference to JQuery. The <script> requires #textbox in the DOM for it to subscribe to keyup event. Hence the script should be placed at the end of the body. This way #textbox is added to DOM by the time the script runs. <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”></script> <head></head> <body> … Read more

[Solved] JavaScript Validation not working on while loop

If you enter yes, the JavaScript asynchronously attempts to trigger a page reload. This means that when the event loop isn’t busy doing something else, the browser will be told to reload the page. However, the event loop is permanently busy because counter==0 so the while loop will never end. You need to exit the … Read more