I have list view in jQuery Mobile web app this list view is made of elements like this:
<li id='search_r'>
<a href='#' id='$id' class='s_result'></a>
</li>
<li id='search_r'>
<a href='#' id='$id' class='s_result'></a>
</li>
Number of element depends on number of search results, its not only these two.
When I click on element in list view, in this case:
<li></li>
I need 2 things to happen, one is to assign the ‘id’ attr from “a” tag inside this specific “li” tag (the clicked one), to the global variable I have called ‘search_r’. The click event works fine, but to get attribute from “a” tag I can’t manage to do.
Here is my js:
$("#cc_page").ready(function(){
$("#search_r").live('click', function(){
search_r = $(this).attr('id');
window.location.href = "http://imes.********.com/app/userpanel.html#sfpp_page";
});
});
I know “this” is not solution. I’m really new to js so that’s why I’m asking such an ridiculous questions 🙂
The first problem you’ve got is duplicate
search_rid attributes, which is invalid. These should be changed to classes. Also, you should be usingon()with a delegate handler, aslive()has been removed from the latest version of jQuery. Try this:I also assume the
$idin your HTML is from some form of templating engine which gets interpreted? If not, those will also need to be made unique.