Yahoo
Yahoo

Reputation: 4187

jQuery Selector equivalent of javascript

I am trying to get the jquery equvaliant of this javascript

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 ?

Upvotes: 1

Views: 356

Answers (3)

indika
indika

Reputation: 11

I think you need to get the child elements based on their class. So try this.

$('#' + id ).find('.addcomment').show();

Upvotes: 1

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123377

$('#' + id + '.addcomment').css('display','block');

as a sidenote in the page you should have only one element with that id, so

$('#' + 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)

Upvotes: 4

thecodeparadox
thecodeparadox

Reputation: 87073

$('.addcomment', '#' + id).css('display','block');

or just simple

$('#' + id).css('display','block');

Upvotes: 1

Related Questions