I have this array:
var names = [
"Name1",
"Name2",
"Name3"
];
I converted this to Unorder List
for HTML:
for(i = 0; i < names.Length; i++){
text += "<li>" + names[i] + "</li>";
}
text += "</ul>";
document.getElementById("choices").innerHTML = text;
Now, I got this:
- Name1
- Name2
- Name3
And I am happy with the result. But now I want if someone click on Name2
so it alert
me the index of the value. What I want is it should in Mobile App (Cordova) so that when user click on List Item it will show details on other activity (Some other page).
PS: I checked:
var index = $( "li" ).index( this );
and
var index = $("ul li.active").index();
But seems like these are not made for me.
May be I should Dynamically assign ID's to each <li>
item? What should I do now?