Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jquery to set html title tag from span element

Posted on 2014-02-12
4
Medium Priority
?
1,833 Views
Last Modified: 2014-02-12
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])
title tag error
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
0
Comment
Question by:Sue White
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 2000 total points
ID: 39854244
Correct me if I'm wrong, but it appears like you are trying to place the text from your span tag into the title?  If that is the case, you need to access the .text() function:

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

Open in new window

0
 

Author Comment

by:Sue White
ID: 39854251
Ah.... so that's what I was missing.  Yes, this works!  Thank you very much.
0
 

Author Closing Comment

by:Sue White
ID: 39854254
thanks for the accurate and speedy reply
0
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 39854260
You are welcome.  Glad to help, and thanks for the points!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question