Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - find child with a specific class

I am trying to write code to search all children for a div that has a specific class. The DIV does not have an ID. Here is the HTML I will be using.

<div class="outerBUBGDiv"> <div class="innerBUBGDiv"> <div class="bgHeaderH2">Technology Group</div> <div class="bgBodyDiv"> <div align="center"> <img height="33" border="0" width="180" src="/heading.jpg"/>   /////other stuff here///// </div> </div> </div> 

Any ideas how I can get the text inside the div with the class bgHeaderH2.

Thanks in advance.

Comment added, didn't explain this very well initially)

like image 827
Caroline Avatar asked Dec 03 '09 11:12

Caroline


People also ask

How would you find a child element with a specific class using jQuery?

children() is an inbuilt method in jQuery which is used to find all the children element related to that selected element. This children() method in jQuery traverse down to a single level of the selected element and return all elements. Here selector is the selected element whose children are going to be found.

How do you get the children of the $( this selector?

Answer: Use the jQuery find() Method You can use the find() method to get the children of the $(this) selector using jQuery. The jQuery code in the following example will simply select the child <img> element and apply some CSS style on it on click of the parent <div> element.

How do you target a class in jQuery?

In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.

What is $() in jQuery?

$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.


1 Answers

$(this).find(".bgHeaderH2").html(); 

or

$(this).find(".bgHeaderH2").text(); 
like image 182
Ryan Avatar answered Sep 19 '22 13:09

Ryan