Question

I'm really stuck .. I need urgent advice :D here is my html :

<!-- Beginning of ROW !-->
<div id="row1">
 <div id="entry">
  free
  <span>some text</span>
  <p>DKK</p>
  <input type="radio" name="red<% Response.Write(counter); %>" id="radio" value="0" />
 </div>

 <div id="entry">
  week
  <span></span>
  <p>DKK</p>
  <input type="radio" name="red<% Response.Write(counter); %>" id="radio2" value="75" />
 </div>
</div>
<!-- End of ROW !-->

<!-- Beginning of ROW !-->
<div id="row2">
 .... same as in row 1
</div>
<!-- End of ROW !-->

nth row ..

Here is Jquery :

$("input").click(function() {
     $("input").parent("div").css("background", "url(images/div_bg.png)");
     $(this).parent("div").css("background", "url(images/div_bg_hover.png)");
});

What I'm trying to do .. is when I select a radio input the div in which it is located should change background and it works perfectly if there is only one row, but for instance if I try to select the value in first row then I select value in second row.. the div in second row where radio input is located changes background as it should but the div in first row reverse itself to other background although input remained checked .. here is what I'm trying to achieve

alt text

And here is what I achieve :

alt text

Was it helpful?

Solution

What is the purpose of your second line of jquery?

$("input").parent("div").css("background", "url(images/div_bg.png)");

This is going to reset the background of all the "entry" divs. If I understand your objective correctly I think you want:

$(this).parent("div").siblings("div.entry").css("background", "url(images/div_bg.png)");

That way only the siblings of the entry you are changing will get their backgrounds reset.

On a side note, you have multiple divs with the same id, which is not a good idea.

OTHER TIPS

This line: $("input").parent("div").css("background", "url(images/div_bg.png)" is causing all of the other items to reset to normal, allowing you to only have 1 active state at a time. You could scope it to the row so that each row may have one item selected.

You're only assigning behavior to the item clicked, rather than all selected input boxes. You might want to make a function as such:

function foo()
{
   $('input :selected').css(bar);
}

Now whenever you get a click event on an input event, call bar. You may need to modify foo to meet your specifications.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top