Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - selectors - Selecting every element within a div

Is there an easy way to select all elements within a div (or any other element) with jQuery?
I have been searching for hours this week and I will continue to bang my head against my keyboard.

<div class="Someclass">
    <img src="" title="" />
    <ul>
        <li></li>
        <li><a href="" alt="" /></li>
    </ul>
</div>

I want an easy way to select all elements within .Someclass without having to call out each element.

like image 849
Jon Avatar asked Mar 15 '11 02:03

Jon


People also ask

How do I select all elements in a div?

The * selector selects all elements. The * selector can also select all elements inside another element (See "More Examples").

How will you select all the div elements on the page using jQuery?

The jQuery syntax is a little simpler, but not much more: $("div") is the jQuery equivalent to document. getElementsByTagName("div") . Here is the API documentation on jQuery's element selector: “Description: Selects all elements with the given tag name.

Can you use CSS selectors in jQuery for selecting elements?

Projects In JavaScript & JQueryjQuery uses CSS selector to select elements using CSS. Let us see an example to return a style property on the first matched element. The css( name ) method returns a style property on the first matched element. name − The name of the property to access.


1 Answers

The easier jQuery only selection would be $("#divID *"). As you know in CSS a b means all b which is descendant of a and a > b means all b which is direct child of a so #myDiv * means everything that is a descendant of a <div> with id="myDiv".

like image 175
AbiusX Avatar answered Nov 01 '22 00:11

AbiusX