[英]jQuery Selector equivalent of javascript
I am trying to get the jquery equvaliant of this javascript 我正在尝试获取此javascript的jQuery等值
var id = $(this).parent().parent().parent().attr("id");
document.getElementById(id).getElementsByClassName("addcomment")[0].style.display = 'block';
but its not working 但它不起作用
$('#+id+' '.addcomment').css('display','block');
Any suggestions ? 有什么建议么 ?
$('#' + id + '.addcomment').css('display','block');
as a sidenote in the page you should have only one element with that id, so 作为页面中的一个旁注,您应该只有一个具有该ID的元素,因此
$('#' + id ).css('display','block');
should works too (of course only if classname it's not necessary to target it, since this is a different selector) 应该也可以工作(当然,仅当类名是不必要的时候,因为这是一个不同的选择器)
$('.addcomment', '#' + id).css('display','block');
或简单
$('#' + id).css('display','block');
I think you need to get the child elements based on their class. 我认为您需要根据其类获取子元素。 So try this.
所以尝试一下。
$('#' + id ).find('.addcomment').show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.