Link to home
Start Free TrialLog in
Avatar of Sue White
Sue WhiteFlag for United States of America

asked on

jquery to set html title tag from span element

I am trying to set an html page <title> tag with text on the page.  The page is a dynamic page, so I want the page title to change depending on the dynamic page opened - which will have different text on every page.

I'm close to getting this to work - but I need help with my jquery syntax.  I don't fully understand how to set this with jquery, so I'd appreciate a little information about how/why your recommendation will work vs. what I did that is almost working.

This is my script:

<script>
            $(document).ready(function () {
                var strTitle = $('.resourcetitle');
                $(document).attr('title', strTitle);
            });
        </script>

Open in new window


This is what renders in the title tag and browser tab (in correctly displaying [object Object])
User generated image
This is how the text on the page is wrapped on the page:
<tr>

    <td class="ms-vb" width="25%"></td>
    <td class="ms-vb" width="75%">
        <span class="resourcetitle"></span>
    </td>

</tr>

Thank you in advance for a reply.
tag1.png
ASKER CERTIFIED SOLUTION
Avatar of OmniUnlimited
OmniUnlimited
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sue White

ASKER

Ah.... so that's what I was missing.  Yes, this works!  Thank you very much.
thanks for the accurate and speedy reply
You are welcome.  Glad to help, and thanks for the points!