jQuery Articles

Page 30 of 42

Place an H1 element and its text at a particular index in jQuery

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 594 Views

To set an element and it’s text, use the text() method in jQuery. With that, use the :nth-child selector to place it at a particular position. Following is the code −Example Document JavaScript MySQL MongoDB Java C#    $('h1:nth-child(4)').text("Python"); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −

Read More

jQuery .val change doesn't change input value?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 4K+ Views

For this, you need to use attr(). The attr() method can be used to either fetch the value of an attribute from the first element in the matched set or set attribute values onto all matched elements.Following is the JavaScript code −Example Document $('#myURL').attr('value', 'http://www.facebook.com'); To run the above program, just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VSCode Editor.OutputLook at the above sample output the URL has been changed from ...

Read More

Adding options to a using jQuery?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 179 Views

To add options to a , you need to use append(). Following is the JavaScript code −Example Document Book TV    var mySelection = new Option("Mobile", "Samsung Mobile");    $(mySelection).html("Samsung Mobile");    $("#selectCategory").append(mySelection); To run the above program, save the file name anyName.html(index.html) and right-click on the file and select the option open with live server in VS Code editor.Output

Read More

jQuery Misc param() Method

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 200 Views

The param() method in jQuery is used to create a serialized representation of an array or object.SyntaxThe syntax is as follows −$.param(obj, val)Above, obj is the object to serialize, whereas Val specifies whether or not to use the traditional style of param serialization.ExampleLet us now see an example to implement the jQuery param() method−    $(document).ready(function(){       ob = new Object();       ob.stdid = "S01";       ob.roll = 3;       $("button").click(function(){          $("p").text($.param(ob));       });    }); Student Details Serialized Representation OutputThis will produce the following output−Click on the button to get serialized representation−

Read More

jQuery dequeue() with Examples

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 276 Views

The dequeue() method in jQuery is used to remove the next function from the queue and then execute the function.SyntaxThe syntax is as follows −$(selector).dequeue(queue)Above, the queue is the name of the queue.ExampleLet us now see an example to implement the jQuery dequeue() method −    $(document).ready(function(){       $("button").click(function(){          var div = $("div");          div.animate({height: 250}, "slow");          div.animate({left: "+=200", top: "+=100" }, "slow");          div.queue(function(){             div.dequeue();          });         ...

Read More

jQuery hide() with Examples

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 364 Views

The hide() method in jQuery is used to hide selected elements.SyntaxThe syntax is as follows −$(selector).hide(speed, easing, callback)Above, the parameter speed is the speed of the hide effect, whereas easing is the speed of the element in different points of the animation. The callback function is a function that executes after hide() method completes.ExampleLet us now see an example to implement the jQuery hide() method  −    $(document).ready(function(){       $(".btnhide").click(function(){          $("p").hide();       });       $(".btnshow").click(function(){          $("p").show();       });    }); ...

Read More

jQuery data() with Examples

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 684 Views

The data() method in jQuery is used to attach data to or gets data from selected elements.SyntaxThe syntax is as follows −$(selector).data(name) $(selector).data(name, value)Above, the name is the name of data to retrieve for the 1st syntax.For the 2nd syntax, the name is the name of data to set, whereas value is the value of data to set.ExampleLet us now see an example to implement the jQuery data() method −    $(document).ready(function(){       $(".button1").click(function(){          $("div").data("student", "Jack Sparrow");          alert("Student Name = " +$("div").data("student"));       });   ...

Read More

jQuery Traversing Siblings

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 236 Views

With jQuery, you can easily find siblings of an element using the following methods: next(), nextAll(), prev(), prevAll(), siblings(), etc. Let us see some of them traverse siblings−next() methodThe next() method is used to return the next sibling element of the selected element. Let us see an example−Example div {    width:600px; } .demo * {    display: block;    border: 2px solid orange;    color: blue;    padding: 10px;    margin: 10px; }    $(document).ready(function(){       $("h3").next().css({"color": "gray", "border": "3px dashed blue"});    }); parent sibling sibling ...

Read More

How to validate email using jQuery?

Kristi Castro
Kristi Castro
Updated on 11-Mar-2026 12K+ Views

To validate email using jQuery, use the regex pattern. You can try to run the following code to learn how to validate email using jQuery −Example               $(document).ready(function() {       $('.error').hide();       $('#submit').click(function(){         var name = $('#name').val();         var email = $('#email').val();         if(name== ''){           $('#name').next().show();           return false;         }         if(email== ''){           $('#email').next().show(); ...

Read More

How to iterate over arrays and objects in jQuery?

David Meador
David Meador
Updated on 11-Mar-2026 1K+ Views

To iterate over arrays and objects in jQuery, use the jQuery forEach() loop. You can try to run the following code to learn how to iterate over arrays and objects −Example $(document).ready(function(){   $("#button1").click(function(){     var arr = [{subject: "Maths", id:3}, {subject: "History", id:7}];     arr.forEach(function(el, index) {       alert(el.id+" "+el.subject);     });   }); });   Result

Read More
Showing 291–300 of 413 articles
« Prev 1 28 29 30 31 32 42 Next »
Advertisements