www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to insert this into the dom.

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Posts
    11

    How to insert this into the dom.

    Hi everyone,

    I was wondering how to insert this dinamically into the Dom with javascript, how would you escape this:

    <div id="div-gpt-ad-1333883367415-15" style="width:300px; height:250px;"><script type='text/javascript'>
    googletag.cmd.push(function() { googletag.display('div-gpt-ad-1333883367415-15'); });
    </script></div>

    Thank You

  2. #2
    Join Date
    Mar 2011
    Posts
    1,108
    I believe this should do it:
    Code:
     var myDiv = document.createElement('div');
     myDiv.setAttribute('id', 'div-gpt-ad-1333883367415-15');
     myDiv.setAttribute('style', 'width:300px; height:250px;');
     var myScript = document.createElement('script');
     myScript.setAttribute('type', 'text/javascript');
     var myCode = "googletag.cmd.push(function() { googletag.display('div-gpt-ad-1333883367415-15'); });";
     myScript.innerHTML = myCode;
     myDiv.appendChild(myScript);
     document.getElementById('???').appendChild(myDiv);
    where '???' is the id of the element where you want to insert this content.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jan 2010
    Posts
    11
    Quote Originally Posted by rtrethewey View Post
    I believe this should do it:
    Code:
     var myDiv = document.createElement('div');
     myDiv.setAttribute('id', 'div-gpt-ad-1333883367415-15');
     myDiv.setAttribute('style', 'width:300px; height:250px;');
     var myScript = document.createElement('script');
     myScript.setAttribute('type', 'text/javascript');
     var myCode = "googletag.cmd.push(function() { googletag.display('div-gpt-ad-1333883367415-15'); });";
     myScript.innerHTML = myCode;
     myDiv.appendChild(myScript);
     document.getElementById('???').appendChild(myDiv);
    where '???' is the id of the element where you want to insert this content.
    Wow man!!!! thanks so much for your help, ill give it a go and let you know how i go

  4. #4
    Join Date
    Jan 2010
    Posts
    11
    by the way how long did that take you to figure out, that was too quick, ive been trying to do this all day.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles