getaway
getaway

Reputation: 8990

changing div's using jquery problem?

i have this click function note when clicked it should change a couple of css values using jquery, here goes:

$('a.note').click(function(){
     $('#leftpanel').css('border-left-width', '20px');
      $('#commentbox').css('visibility', 'hidden');
     $('.date').css('visibility', 'visible');
});

html:

<div id="leftpanel>blahbalhbalh number 1</div>
<div id="leftpanel>blahbalhbalh number 2</div>

but the jquery only chnages the css of the first leftpanel div, and not the second one, how can i resolve this or is thier a problem, thanks!!!!

Upvotes: 0

Views: 89

Answers (1)

Sarfraz
Sarfraz

Reputation: 382909

The id should be unique per element per page, that's your problem, you should do:

<div id="leftpanel">blahbalhbalh number 1</div>
<div id="leftpanel2">blahbalhbalh number 2</div>

Or you can use same class instead if you want:

<div class="leftpanel">blahbalhbalh number 1</div>
<div class="leftpanel">blahbalhbalh number 2</div>

And then you can use jQuery to target via class as well.

Upvotes: 1

Related Questions