0

I am trying to select my radio button value within multiple divs but i don't know.

Also, append text within table but it doesn't work. maybe my syntax is wrong?

I've also tried appendTo() but same. nothing appears on the screen

input radio is located..

<div id="wrap">
<div id="section1">
<table class="question">
<tr><td><input type="radio" value="yes" name="tv"/></td><td><p id="position"></p></td></tr>
</table>
</div>
</div>

And below is my jquery source in script.js

$('#section1.input:radio["tv"]').change(function(){
    if ($(this).val() == 'yes') {
       $('#position').append("test appending");
});

1 Answers1

1

Your selector is totally wrong.

  • input shouldn't be prefixed by a dot, it isn't a CSS class ;
  • You need a space between #section1 and input, since the input is a child of your div ;
  • You forgot name= in the brackets.

Try something like:

$('#section1 input:radio[name="tv"]').change(function(){
    if ($(this).val() == 'yes') {
       $('#position').append("test appending");
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrap">
  <div id="section1">
  <table class="question">
   <tr>
      <td>
        <input type="radio" value="yes" name="tv"/></td><td><p id="position"></p>
      </td>
    </tr>
  </table>
  </div>
</div>
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97