Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selecting and filtering elements inside a div

People also ask

How do I select all elements in a div?

getElementsByTagName() that will select all the instances of a certain HTML element on the current webpage based on its tag name, i.e. <div> . Calling document. getElementsByTagName("div") is all you need to do to select all <div> elements on the current page using JavaScript.

How do we filter out elements using jQuery?

The filter() method returns elements that match a certain criteria. This method lets you specify a criteria. Elements that do not match the criteria are removed from the selection, and those that match will be returned. This method is often used to narrow down the search for an element in a group of selected elements.

Which is the correct jQuery selector statement to select all div elements?

13. Which is the correct jQuery selector statement to select all <div> elements? Explanation: The statement $("div") is the correct syntax to select all <div> elements.

What is the main difference between selectors and filters jQuery?

jQuery selector selects all elements based on the elements name given by you. jQuery filter( ) adds further detail to the selected elements by specifying the criteria of selection.


$("#wrapper input[type=button]").click(function() {
    alert("hi there");
});

use id for a specific button-

<div id="wrapper">
    <input type="text" value="you can edit me">
    <input type="button" id='btnMyButton' value="click me">
    <input type="button" class='btnClass' id='btnMyButton2' value="click me 2">
<input type="button" class='btnClass' id='btnMyButton3' value="click me 3">
</div>

$('#btnMyButton').click(function(){
alert("hi there");
});

For all buttons in the div, follow John's answer. Use class for some buttons-

$('.btnClass').click(function(){
    alert("all class");
});

btw, i like to put my all jquery function inside ready function like-

$(document).ready(function(){        

});