Interview Questions Answers.ORG
Interviewer And Interviewee Guide
User Interface Expert Interview Question:
How would we select the 3rd li element and retrieve the value of it's id attribute w/out selecting the li by id? *You can select it by index?
<ul id="list">
<li id="one"></li>
<li id="two"></li>
<li id="three"></li>
<li id="four"></li>
</ul>
Submitted by: Muhammad$('ul li').eq(2).attr('id');
// or
var item;
$.each($('ul li'), function(i){
if (i == 2){
item = $(this).attr('id');
}
});
Submitted by: Muhammad
// or
var item;
$.each($('ul li'), function(i){
if (i == 2){
item = $(this).attr('id');
}
});
Submitted by: Muhammad
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.