1

i have a div that has a ul elemenet having class="bla" and id="foo"

<div class = new>
<ul class="bla" id="foo"><li>aa</li></ul>
</div>

how can i get id of the ul,, help is appreciable

Jot Dhaliwal
  • 1,470
  • 4
  • 26
  • 47

5 Answers5

1

Try this:

var myEl = $('ul.bla').attr('id');
isherwood
  • 58,414
  • 16
  • 114
  • 157
1
$('.new ul.blah').attr('id')

specifc to uls, and the new container div

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
0
$('ul[class=bla]').prop('id')

Will look up the ul element with the specific class bla.

prop('id') will get it's id.

JamesA
  • 365
  • 3
  • 11
0

Try this:

$('div.new').find('ul.bla').attr('id');
Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38
-1

The id is considered a property of the ul, similar to the class and can both be used as selectors, so to use JQuery. you would use the class as the selector for the ul, and then access the ul property id.

$( '.class' ).prop( 'id' );

In this case it would return 'foo'.

EDIT ------

After seeing that you want to use those id's to select them, you could use one of these two methods.

var list = $( '#id' );

or

var list = $( '.class#id' );

The first method will work, but the second method is more explicit. Either one is acceptable though.

PugsOverDrugs
  • 515
  • 1
  • 4
  • 14