How can i change the css of 'My data'. Whenever user clicks on input radio, My data should change its text color. how to access it, as it is sibling of input whose id is 'b'. Please tell me both the ways, strong text accessing by parent and by sibling.strong text
<tr>
<td>
<input type='radio' id='b' name='option' value="b">
My data
</td>
</tr>
You can also try this:
$('#b').click(function(){
$(this).closest('td').text().css("color","red");
});
Firstly you cannot style text, only elements. So you should wrap that text in a span or something. Then you can use the adjacent sibling selector to select in depending on the state of the radio button.
<tr>
<td>
<input type='radio' id='b' name='option' value="b">
<span>My data</span>
</td>
</tr>
#b:checked + span{
color: red;
}
You can style the parent TD with this jquery:
$("#b").closest("td").css("color", "red")
Or something like that, I suppose you know css(...)
I think you should put 'My data' in a div tag in order to manipulate it easier. I mean something like this:
<tr>
<td>
<input type='radio' id='b' name='option' value="b">
<div id="my_data"> My data </div>
</td>
</tr>
If you try this then with jquery you can do:
$('#b').click(function(){
$(this).next('#my_data').css('color', 'red');
});