Zwen2012
Zwen2012

Reputation: 3498

jQuery: How to find a li-tag with a specific id

I have a <ul> with many <li>. My <li>'s have different id's: for example: <li class="image" id=1>....</li> How can I find now this <li> with the id=1 ?? I tried this-->

var deleteImage =  $("ul").find( ".image" ).attr("id").val(1);

...but it doesnt work. Any idea? THANKS!!!

Upvotes: 1

Views: 17927

Answers (3)

Thomas Bormans
Thomas Bormans

Reputation: 5354

ID's should never start with numbers. Change your id's to image1, image2, image3, ... Then use:

$('#image1').functionToExecute();

Upvotes: 5

John McManigle
John McManigle

Reputation: 116

The id tag is supposed to be unique within the HTML document. So, assuming you've constructed the HTML appropriately, you should be able to select the li tag with just:

$('#1')

Upvotes: 0

Antoine Combes
Antoine Combes

Reputation: 1454

This is a basic JQuery/CSS selector:

var deleteImage =  $("ul").find( "#1.image" );

Upvotes: 6

Related Questions