Bạn đang xem: Jquery misc index() method
On each li click I vị this function:
var str = $("#amastorage li").index();alert(str);Which always give"s me 8.
EDIT:
This is how I get it:
$("#amastorage ul").find("a").click(function () var str = $("#amastorage li").index(); alert(str););I cant change: $("#amastorage ul").find("a").click(function () { because It"s from a plugin and it won"t work.
Thanks
How can I alert the li number I choosed?

You need lớn use the this object in the click function.
Xem thêm: Tải Game Prehistoric Park Hack, Tải Về Idle Prehistoric Park Theme Park Tycoon V0
http://jsfiddle.net/kuJWc/
$("li").click(function() var str = $(this).index(); alert(str););per your edit:
$("#amastorage ul").find("a").click(function () var str = $(this).parents("li").index(); alert(str););

You"ll want lớn loop through all the children of the ul and assign a click handler to each li lượt thích so:
$("#amastorage").children().each(function(i) $(this).click(function() var index = i; alert(index); ););Here"s an example in action: http://jsfiddle.net/qAuUe/

Thanks for contributing an answer lớn Stack Overflow!
Please be sure to answer the question. Provide details and share your research!But avoid …
Asking for help, clarification, or responding to lớn other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.
Post Your Answer Discard
By clicking “Post Your Answer”, you agree lớn our terms of service, privacy policy và cookie policy
Not the answer you're looking for? Browse other questions tagged jquery indexing or ask your own question.

Site thiết kế / hình ảnh sản phẩm © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. Rev2022.5.18.42164
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.