Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  139] [ 3]  / answers: 1 / hits: 41587  / 12 Years ago, mon, july 23, 2012, 12:00:00
<div id=ChosenCategory class=chosen>
<div class=cat_ch name=1>
<div class=cat_ch name=2>
<div class=cat_ch name=3>
<div class=cat_ch name=5>
<div class=clear> </div>
</div>


I want to loop though div.cat_ch How?



This one fails:



    $(div).each(function () {
alert(FW);
alert($(this).attr(name).val());
});

More From » jquery

 Answers
4

http://jsfiddle.net/2TRxh/



I think your issue lies with the attempt to get the val off the div after you get the attribute $(this).attr(name).val(). Using .val() on a div doesn't make sense. If you remove that $(this).attr(name) returns the name property off the divs. You can further specify the div's to loop through by using the class selector in your each rather than just div. $(.cat_ch).each(function () {}); This has been shown in various other answers to this question.


[#84076] Sunday, July 22, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylee

Total Points: 60
Total Questions: 119
Total Answers: 101

Location: Bonaire
Member since Wed, Mar 29, 2023
1 Year ago
;