Szymon Toda
Szymon Toda

Reputation: 4516

jQuery how to select parent of element

I have this elements:

<div class="ELEMENT_LISTY" style="">

<div class="TITLE" id="174">string</div>
<div class="BUTTONY">
  <div class="POGLAD"></div>
  <div class="ZMIEN_NAZWE"></div>
  <div class="USUN"></div>
</div>

</div>

How to select element with class .ELEMENT_LISTY only when I have id #174?

Upvotes: 1

Views: 83

Answers (3)

You can do:

if ( $('div#174').length ) { //if element #174 exists
   $('div.ELEMENT_LISTY').whatever..
}

Upvotes: 0

Brian Hoover
Brian Hoover

Reputation: 7991

This should work.

$('#174').parents('.ELEMENT_LISTY')....

Upvotes: 1

user1026361
user1026361

Reputation: 3657

$('#174').parent()

would do it.

It should be noted that mumerical IDs can be tricky within browsers..you should consider using IDs that start with a letter.

Upvotes: 6

Related Questions