Amit D has Published 118 Articles

How can I change the text color with jQuery?

Amit D

Amit D

Updated on 17-Feb-2020 05:13:42

10K+ Views

To change the text color with jQuery, use the jQuery css() method. The color css property is used to change text color.ExampleYou can try to run the following code to learn how to change text color with jQuery −Live Demo $(document).ready(function(){     $("p").on({     ... Read More

How to return variable value from jQuery event function?

Amit D

Amit D

Updated on 17-Feb-2020 05:10:34

2K+ Views

You cannot return variable value from jQuery event function. To understand the reason, let us see how data is passed, which was created in the event handler of a button click.ExampleLive Demo $(document).ready(function(){     var a=document.getElementById('demo');     a.addEventListener('click', function(){        var s='Hello ... Read More

What is the difference between event.preventDefault() and return false in jQuery?

Amit D

Amit D

Updated on 14-Feb-2020 11:20:51

465 Views

Returning false from jQuery event handlers is like calling both preventDefault() and stopPropagation(). The preventDefault() method prevents the browser from executing the default action.ExampleYou can try to run the following code to run event.preventDefault() method in jQuery −Live Demo           jQuery preventDefault() method     ... Read More

How do I prevent jQuery events from bubbling up to parent elements?

Amit D

Amit D

Updated on 14-Feb-2020 11:05:15

1K+ Views

To prevent jQuery events from bubbling up to parent elements, use the stopPropogation() method. The stopPropagation() method stops the bubbling of an event to parent elements, preventing any parent handlers from being notified of the event.ExampleYou can try to run the following code to prevent jQuery events from bubbling up ... Read More

How to stop the bubbling of an event to parent elements in jQuery?

Amit D

Amit D

Updated on 14-Feb-2020 11:04:20

186 Views

To stop the bubbling of an event to parent elements, use the stopPropagation() method. You can try to run the following code to learn how to stop the bubbling of an event to parent elements −ExampleLive Demo           jQuery stopPropagation() method       ... Read More

How to prevent the browser from executing the default action in jQuery?

Amit D

Amit D

Updated on 14-Feb-2020 10:41:19

641 Views

To prevent the browser from executing the default action in  jQuery, use the preventDefault() method. The preventDefault() method  prevents the browser from executing the default action.ExampleYou can use the method isDefaultPrevented() to know whether this method was ever called (on that event object).Live Demo           ... Read More

How can I remove all elements except the first one using jQuery?

Amit D

Amit D

Updated on 14-Feb-2020 10:15:16

2K+ Views

To remove all elements except the first one, use the remove() method with the slice() method in jQuery. You can try to run the following code to remove all elements except for first one using jQuery −ExampleLive Demo $(document).ready(function(){     $(".button1").click(function(){         ... Read More

How to remove all child nodes from a parent using jQuery?

Amit D

Amit D

Updated on 14-Feb-2020 10:14:03

4K+ Views

To remove all child nodes from a parent, use the empty() method. The empty() method removes all child nodes from the set of matched elements.ExampleYou can try to run the following code to learn how to remove all child nodes from a parent −Live Demo         ... Read More

How to use jQuery.insertAfter() method in jQuery?

Amit D

Amit D

Updated on 14-Feb-2020 10:12:54

94 Views

The insertAfter( selector ) method inserts all of the matched elements after another, specified, set of elements.Here is the description of all the parameters used by this method −selector − Content after which the selected element(s) is inserted.ExampleYou can try to run the following code to learn how to use jQuery.insertAfter() ... Read More

How to use jQuery.insertBefore() method in jQuery?

Amit D

Amit D

Updated on 14-Feb-2020 10:08:34

215 Views

The insertBefore( selector ) method inserts all of the matched elements before another, specified, set of elements. Here is the description of all the parameters used by this method −selector − Content before which the selected element(s) is inserted.ExampleYou can try to run the following code to learn how to use ... Read More

Advertisements