Search code examples
jqueryclickliveattr

jquery on click not retaining value?


i have this situation:

$id = 123456;

<a href="<?=$id?>" id="id"></a>
<a href="100" id="count">100</a>

$('#count').live("click", function() {
    var votes = $("#count").attr("href");
    var id= $("#id").attr("href");
    var dataStrings = 'id=' + id+ '&votes=' + votes;
});

if i do a alert or console log i get only the count value: id=undefined&votes=100

any ideas on what the problem might be?

thanks

edit:

the $id var is a php one. and if i view source i see the number being echoed there:

<a href="123456" id="id"></a>
<a href="100" id="count">100</a>

Solution

  • It is possible that you have another element in your html with a duplicate id="id" but without "href" attribute before the code you posted here.