homepage Welcome to WebmasterWorld Guest from 54.167.11.16
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Use JQuery to append content on page to other elements
rwilson




msg:4378498
 2:26 am on Oct 24, 2011 (gmt 0)

I'm limited to using only one include on a page for a content management system and I want to take the content of the <h1> within this include and append it elsewhere on the page using JQuery.

So I want it to read a specific <h1> and append inside the title meta tag and an <h3> tag. Is this possible? Any help would be greatly appreciated!

 

enigma1




msg:4379774
 9:28 pm on Oct 26, 2011 (gmt 0)

To get the text and assuming you have a single h1 in the page,

html:
<div><h1>Header</h1></div>
<div><h3 class="subhead">Sub-Heading</h3></div>

jquery:
var h1_text = $('h1').text();
var title = $('title').text();
$('title').text(title+h1_text);

Not sure what you meant with h3. If you meant to get the h3 too just add another var and append it.
var subhead = $('.subhead').text();
...

rwilson




msg:4379818
 10:48 pm on Oct 26, 2011 (gmt 0)

That's exactly what I needed. Thank you very much!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved