从 this.parent 获取 ID [英] Get ID from this.parent
本文介绍了从 this.parent 获取 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试通过 $(this).parent() 使用 javascript 获取 div 的 id 名称.
Trying to get the id name of a div using javascript when it is going by $(this).parent().
下面的Javascript代码:
Javascript Code below:
$(function() {
$('a.close').click(function() {
$(this).parent().fadeOut(1500);
$.cookie($(this).attr('id'), 'true', { expires: null});
alert($.cookie($(this).attr('id')));
return false;
});
if($.cookie('hidden') == 'true'){
$('#errororganinfoinchide-this').hide();
}
});
试图从下面的 HTML 中获取 id errororganinfoinchide-this.尝试这种方式,因为该 ID 可能因页面而异.
Trying to get the id errororganinfoinchide-this from the HTML below. Trying this way as that id can vary from page to page.
<aside class='warning' id='errororganinfoinchide-this'>
<a href='#errororganinfoinchide-this' class='close'><img src='http://resources.site.co.nz/backgrounds/close.png' /></a>
<img src='http://resources.site.co.nz/backgrounds/icon_warning.png' class='messageimg' />
<h4>Warning - Organisation Info</h4>
<p>Sorry, there was an error opening the "Organisation Info" Box. Please try again later.</p>
</aside>
非常感谢所有帮助.谢谢.
All help greatly appreciated. Thanks.
推荐答案
你是否尝试过这样的事情:
Have you tried something like this:
$(this).parent().attr('id')
这篇关于从 this.parent 获取 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文