- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 8895 Articles for Front End Technology
204 Views
To fetch the nth div from an HTML page, use the jQuery eq() method. It is used to access the index of an element in jQuery. The eq() method refers the position of the element.ExampleYou can try to run the following code to learn how to fetch nth div from an HTML page using jQuery. Here, we will fetch the 2nd div:Live Demo $(document).ready(function(){ $("#button1").click(function(){ alert($("div:eq(1)").text()); }); }); Paragraph One Paragraph Two - 2nd div selected Paragraph Three Which div?
781 Views
Here’s how you can get objects by ID Selector (#id), by Class Selector (.class), by Tag, and Attribute (.attr()).Get Object by Class SelectorExampleThe element class selector selects all the elements which match with the given class of the elements.Live Demo jQuery Selector $(document).ready(function() { $(".big").css("background-color", "yellow"); }); This is first ... Read More
326 Views
To escape square brackets in jQuery selectors is quite easy. Let’s see with an example of escaping the brackets in the name of the box.ExampleWhatever you will select, will get added to the textarea on button click.Live Demo $(document).ready(function() { $("#addnow").click(function () { $("#myselect :selected").each(function () { $("#text").val($("#text").val() + $(this).text() + ""); }); }); }); email@example.com David Select and Click to Add
3K+ Views
ExampleYou can try to run the following code to write a jQuery selector to find links with # in href. Here,^ is used to find links starting with # in href.Live Demo $(document).ready(function(){ $('a[href^="#"]').click(function(){ alert('Success! Selected link starting with # in href.'); }); }); Demo C++
612 Views
It’s quite easy to use JavaScript variables in jQuery selectors.ExampleLet’s seen an example to use JavaScript variables in jQuery to hide an element:Live Demo $(document).ready(function(){ $("input").click(function(){ var name = this.name; $("input[name=" + name + "]").hide(); } ); }); Heading 1 To hide the buttons, click on it.
185 Views
If you want to select an element with a specific index, then use the jQuery selector eq(). Here, set the index number to select the element.ExampleYou can try to run the following code to learn how to use jQuery selector eq():Live Demo $(document).ready(function(){ $("p:eq(1)").css("background-color","red"); }); Heading 1 This is demo text. This is another text. This is demo content
292 Views
The $ variable is for jQuery. If you’re using more than one JavaScript library or multiple versions of jQuery, then you should use jQuery(selector) instead of $(selector) to avoid name conflicts.ExampleTo understand the noConflict() concept, let us see an example of using the jQuery (selector):Live Demo $.noConflict(); jQuery(document).ready(function(){ jQuery("button").click(function(){ jQuery("h3").text("jQuery works perfectly"); }); }); Testing jQuery Click below: Click me The $ sign is used for jQuery, but what if other frameworks also use the same $ sign; this may create issues and ... Read More
70 Views
The children( [selector] ) method gets a set of elements containing all of the unique immediate children of each of the matched set of elements.ExampleYou can try to run the following code to learn how to get a set of elements containing all of the unique immediate children of each of the matched set of elements:Live Demo jQuery Example $(document).ready(function(){ $("div").children(".selected").addClass("blue"); }); ... Read More
72 Views
The find( selector ) method can be used to locate all the descendant elements of a particular type of elements. The selector can be written using any selector syntax.ExampleYou can try to run the following code to learn how to locate all the descendant elements of a particular type of elements:Live Demo jQuery Example $(document).ready(function() { $("p").find("span").addClass("selected"); }); .selected { color:blue; } This is first paragraph and THIS IS BLUE This is second paragraph and THIS IS ALSO BLUE
678 Views
To exclude first and second element from jQuery, use the slice() method.ExampleYou can try to run the following code to exclude first and element from jQuery:Live Demo $(document).ready(function(){ $('p').slice(2).css('font-size', '24px'); }); Java C++ Ruby Groovy