Question

I've been dealing with an error I can't solve.

I've got an approval task form in which I want to hide the ribbon depending on the value of a field.

The HTML generated when clicking the task link:

... other code... 
    <table border="0" cellspacing="0" width="100%">
<tbody>
    <tr>
        <td width="190px" valign="top" class="ms-formlabel">
            <h3 class="ms-standardheader"><nobr>...</nobr></h3>
        </td>
        <td width="400px" valign="top" class="ms-formbody">...</td>
    </tr>
    <tr>
        <td width="190px" valign="top" class="ms-formlabel">
            <h3 class="ms-standardheader"><nobr>...</nobr></h3>
        </td>
        <td width="400px" valign="top" class="ms-formbody">... </td>
    </tr>
    <tr>
        <td width="190px" valign="top" class="ms-formlabel">
            <h3 class="ms-standardheader"><nobr>...</nobr></h3>
        </td>
        <td width="400px" valign="top" class="ms-formbody">27/02/2015</td>
    </tr>
    <tr>
        <td width="190px" valign="top" class="ms-formlabel">
            <h3 class="ms-standardheader"><nobr>...</nobr></h3>
        </td>
        <td width="400px" valign="top" class="ms-formbody" id="tdResultado">Approved</td>
    </tr>
</tbody>
</table>

My Script:

    <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
    ...
<script src="../SiteAssets/scripts/jquery-1.11.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        _spBodyOnLoadFunctionNames.push("x");

        var x1;

        function x() {
            alert($('#tdResultado'));
        }

    </script>

</asp:Content>

Shows me [object Object].

But when I try to Access its val(), innerHTML(), innerText() or any other property it never returns me the value ("Approved"), it always returns blank.

Everything I'am doing is under Chrome. Any ideas? Thank you

Was it helpful?

Solution

You get [object Object] because you are looking at the toString of the jQuery object. If you use console.log, or a breakpoint, you will see the actual array, then you can even right click and reveal the element (if found) in the elements tab.

Furthermore you can't call innerText on a jQuery object, what you are looking for is text().

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top