tags:

views:

26

answers:

1

A list is created dynamically. Now I want to get 93 or 94 etc which will be used for php function.

For example I added 93 in two ways as you can see below. In li class="93" or href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/93"

Can anyone tell me how to get this number with jquery please?

Thanks in advance.

...
...
<li class="93">
<div class="listbox">
<span class="user"><strong>Administrator</strong></span>
<span class="date">2010-01-28 15:33:53</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/93"
class="todo">to do</a><span class="msg">test</span></div></li>
...

I am working on the following code.

//on todo event. this changes the status to compeleted

$(".todo").live('click', function(event){
event.preventDefault();
// alert("hei");
loading.fadeIn();

});  

This is a follow up question from here. But the question itself is different.

+2  A: 

You can get it from the <li> parent:

$(".todo").live('click', function(event){
  alert($(this).parent("li").attr("class"));
  loading.fadeIn();
  event.preventDefault();    
});

Or take it from the href using the attr() function and take a substring:

$(".todo").live('click', function(event){
  var href = $(this).attr("href");
  alert(href.substring(href.lastIndexOf("/") + 1);
  loading.fadeIn();
  event.preventDefault();    
});
Nick Craver
Thanks. The first one did not work. It gives undefined. But the second one worked adding ) after +1).
shin