Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get attribute of child element

If I have the following markup:

<p class="header hours">     <a href="javascript:void(0)" class="sort" sortcat="hours">         Hours&nbsp;<span class="imgholder" sortcat="hours">&nbsp;</span>     </a> </p> 

How can I target the <span> tag within the anchor tag? There are five other similar <p> tag entries, each with a different value for sortcat=

like image 606
PruitIgoe Avatar asked Jan 19 '11 20:01

PruitIgoe


People also ask

How do I get the div element of all children?

If You want to get list only children elements with id or class, avoiding elements without id/class, You can use document. getElementById('container'). querySelectorAll('[id],[class]'); ... querySelectorAll('[id],[class]') will "grab" only elements with id and/or class.


1 Answers

$(".sort").click(function(){   var cat =  $(this).children("span").attr("sortcat");   //do something with the sortcat }); 
like image 156
mkoryak Avatar answered Oct 26 '22 05:10

mkoryak