1

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

  • 1
    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, jay – eirikb Feb 26 '15 at 18:15
  • Hi @eirikb thank you for your reply. I did as you say and now in the console I see the object and its properties are correct (i.e. InnerText has the value "Approved"). But when I do: console.log($('#tdResultado').innerText()); I get an error : "Uncaught TypeError: undefined is not a function". I've used both _spBodyOnLoadFunctionNames.push() and document.ready()... but the result is always that error. – ADPX Feb 27 '15 at 7:44
  • innerText is a property on HTMLNodes, not a function on a jQuery object, perhaps you are looking for text() – eirikb Feb 27 '15 at 7:45
  • You were absolutely right, now I've got it solved. If you would like to post your reply as an answer I would gladly mark it as correct. Thank You very much :) – ADPX Feb 27 '15 at 7:59
0

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().

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.