-1

Trying to select the textarea inside of the td by the name. None of the normal methods seem to be working:

<script>$(document).ready(function () {
$( document ).on( 'click', 'button', function (event) {
    $(".myForm [name='name']").val('Hello World!');
    $(".myForm td [name='name']").val('Hello World!');
    $(".myForm td textarea [name='name']").val('Hello World!');
    $(".myForm textarea [name='name']").val('Hello World!');
});
});</script>


<table>
<tr>
    <form class="myForm">
        <td>
            <textarea name="name"></textarea>
        </td>
    </form>
</tr>
</table>

<button>click me</button>

        </td>
    </form>
</tr>
</table>

click me

Robbie
  • 700
  • 2
  • 6
  • 18
  • 1
    Putting a `
    ` tag between a `` and a `` is not valid and causes problems. [Working Example](http://jsfiddle.net/dox5rjv1/).
    – showdev Jun 01 '15 at 21:59
  • See: [Which DOM elements can be child of tr?](http://stackoverflow.com/questions/12634715/which-dom-elements-can-be-child-of-tr) – showdev Jun 01 '15 at 22:10

2 Answers2

0

You need to surround your whole table with the form and remove the space between element and attribute selector, i.e. textarea[name='name'].

https://jsfiddle.net/jd7qp4ts/

Matthias
  • 7,432
  • 6
  • 55
  • 88
  • While that does work, you shouldn't need to surround the entire thing should you? That doesn't make sense with the DOM. – Robbie Jun 01 '15 at 22:03
  • @Robbie Well, you're at least not allowed to place it in a [`tr` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr). – Matthias Jun 01 '15 at 22:06
0

Your problem in non-standard wrapping of form element inside table. Check it out here Form tag won't enclose elements inside a table and space, as others have pointed out. Possible solution would be to re-organize your markup.

Community
  • 1
  • 1
roxxypoxxy
  • 2,973
  • 1
  • 21
  • 28
  • Ah, that... kinda makes sense...? Not really, but at least I know what it isn't working. That's kinda squirrely though, regardless. – Robbie Jun 01 '15 at 22:07