Front End Technology Articles

Page 597 of 652

How to change the background color using jQuery?

Amit D
Amit D
Updated on 11-Dec-2019 10K+ Views

To change the background color using jQuery, use the jQuery css() property. We will change background color on mouse hover with the jQuery on() and css() method. ExampleYou can try to run the following code to learn how to change background color using jQuery:Live Demo $(document).ready(function(){     $("body").on({         mouseenter: function(){             $(this).css("background-color", "gray");         },                   mouseleave: function(){             $(this).css("background-color", "red");         },                 dblclick: function(){             $(this).css("background-color", "yellow");         }     }); }); Double click and move the mouse pointer to change the background color.

Read More

How to handle HTML5 media events using jQuery?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 504 Views

To handle HTML5 media events using jQuery, use the click() method.ExampleYou can try to run the following code to learn how to handle HTML5 media events such as playing a song:Live Demo $(document).ready(function(){     var x = $(".myPlayer").length; // Count total audio players     var z = 0; // Start at first audio player     $("#play-bt").click(function(){        $(".myPlayer")[z].play();        $(".message").text("Music started");     })     $("#stop-bt").click(function(){        $(".myPlayer")[z].pause();        $(".myPlayer")[z].currentTime = 0;        $(".message").text("Music Stopped");     }) });   Play music Stop music

Read More

How does jQuery Datepicker onchange event work?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 17K+ Views

To work with jQuery Datepicker onchange(), use the datepicker onSelect event. This will show which date we added currently and changed to.ExampleYou can try to run the following code to learn how to work jQuery Datepicker onchange:Live Demo           $( function() {       $(".date").datepicker({     onSelect: function(dateText) {       display("Selected date: " + dateText + ", Current Selected Value= " + this.value);       $(this).change();     }   }).on("change", function() {     display("Change event");   });   function display(msg) {     $("").html(msg).appendTo(document.body);   }   });       Date:

Read More

How to pass a jQuery event as a parameter in a method?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 3K+ Views

To pass a jQuery event as a parameter in a method, use the bind() method.ExampleYou can try to run the following code to learn how to apss a jQuery event as a parameter:Live Demo $(document).ready(function(){    $("#btn1").bind("click", { key1: "value1", key2: "value2" }, myFunction);    function myFunction (event)    {      $("#myid").text(event.data.key1);    } });

Read More

How to disable right click using jQuery?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 3K+ Views

To disable right click on a page, use the jQuery bind() method.ExampleYou can try to run the following code to learn how to disable right click:Live Demo $(document).ready(function(){    $(document).bind("contextmenu",function(e){       return false;    }); }); Right click is disabled on this page.

Read More

How to fire jQuery events with setTimeout?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 1K+ Views

The jQuery setTimeout() method is used to set an interval for events to fire.ExampleHere, we will set an interval of 3 seconds for an alert box to load using jQuery events:Live Demo $(document).ready(function(){     $("#button1").click(function(){        setTimeout("alert('Hello World!');", 3000);     }); }); Click Click the above button and wait for 3 seconds. An alert box will generate after 3 seconds.

Read More

Is it possible to detect when images are loaded via a jQuery event?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 2K+ Views

To detect loading of an image with jQuery, use the load() event handler.Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.ExampleYou can try to run the following code to learn how to detect when image loads:Live Demo $(document).ready(function(){     $("img").load(function(){         alert("Image successfully loaded.");     }); }); Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.

Read More

How we can prioritize jQuery events?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 1K+ Views

To prioritize jQuery events, use the event.stopPropagation().ExampleYou can try to run the following code to learn how to prioritize using stopPropogation() method:Live Demo $(document).ready(function(){        var timer;    function out(s) {       if (timer) {         clearTimeout(timer);         timer = null;       }       $("#demo").append(s + "");       timer = setTimeout(function() {         $("#demo").append("-------" + "");         timer = null;       }, 100);    }    $(".li").find('input').click(function(e){     out('li>input');     if ($(this).parent().hasClass("stop")) {         e.stopPropagation();     }    });    $(".li").click(function(e){     out('li');    });    $('input').click(function(e){     out('input');     if ($(this).parent().hasClass("stop")) {         e.stopPropagation();     }    }); }); Demo Demo using stop propagation method

Read More

Which jQuery events do not bubble?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 184 Views

Some of the jQuery events, do not bubble such as mouseenter do not bubble. Let us see an example of such events.ExampleYou can try to run the following code to learn how to work with jQuery events, which do not bubble,Live Demo  $(document).ready(function(){     $("p").mouseenter(function(){       $("p").css("background-color", "red");     });     $("p").mouseleave(function(){       $("p").css("background-color", "blue");     });  }); Demo Text - Keep the mouse pointer here.

Read More

How to store and reproduce jQuery events?

Alex Onsman
Alex Onsman
Updated on 11-Dec-2019 231 Views

To store and reproduce jQuery events, use console to log.ExampleYou can try to run the following code to learn how to store and reproduce jQuery events:Live Demo $(document).ready(function(){     window.events = []     $("#track").click(function(event){        window.events.push(event)            $.each(window.events, function(i, item){           console.log(i, item);        });    }); }); Track

Read More
Showing 5961–5970 of 6,517 articles
« Prev 1 595 596 597 598 599 652 Next »
Advertisements