jquery get id of input field

67,273

Solution 1

You might want this :

var id = $('#idEstablishmentRow td.ms-formbody span input').attr('id');

But as your HTML doesn't have any element whose id is idEstablishmentRow, it's hard to be sure of what you exactly want.

Demonstration

Solution 2

var inputId = $("span input").attr("id");
Share:
67,273

Related videos on Youtube

user1652050
Author by

user1652050

Updated on February 23, 2020

Comments

  • user1652050
    user1652050 over 3 years

    i need to get the id of a input that's inside a span of a sharepoint list. it looks like the code below.

    <tr id="idEstablishmentRow">
    <td class="ms-formbody" vAlign="top">
    <span dir="none">
    <span style="vertical-align: middle;">
    <input type='text' id='hello' />
    </span>
    </span>
    </td>
    </tr>
    

    now i want to get the id of the input. i have tried:

        var _test = $('#idEstablishmentRow').find('td.ms-formbody');
        var _test1 = _test.find('span.style');
    
        var _test2 = _test1.find('input');
        var _test3 = _test2.attr('id');
        alert(_test3);
        alert(_test2);
    

    but it didn't work. could anyone help me ?

  • user1652050
    user1652050 over 10 years
    i have a sharepoint list with alot of trs/tds, the idestablishmentrow is the id of the row forgot to put it in sorry.
  • Denys Séguret
    Denys Séguret over 10 years
    So that should work. Maybe you want to replace td with td.ms-formbody too, depending on your real HTML.
  • user1652050
    user1652050 over 10 years
    i have uploaded the actual code. i need the id of the input, if i use your code and try to alert it it says undefined

Related