开发者

How to get the last part in href or grandparent's id with jquery?

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.


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();    
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜