Papermashup

Subscribe


Tweets


"RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…"

@ashleyford 2 days ago

"Is there ever a time that @DFS doesn't have a sale on?"

@ashleyford 6 days ago

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Replace a divs contents with jQuery

AshleyAshley

I had a problem a while back where i needed to put the contents of a div into another div, the reason for this was because i couldn’t access the source code of the page to modify the div contents, as it was built using a CMS, so the only option was to use .append() in jQuery to do the job.

The code.



$(document).ready(function(){
var contentDiv = $('#contentDiv').html();
$('#Container').append(contentDiv);
$('#contentDiv').remove();
 });

You need to include the jQuery framework to get started, with the above configuration we’re taking the div #contentDiv and placing it into #Container, then we remove the original #contentDiv from the page.

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Comments 0
There are currently no comments.