SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display HTML+CSS (as result) with Javascript

    Hi,

    I have an HTML code block with some CSS styling which has multiple sub-elements and I want to display it in another div (in an iframe) using Javascript. What I have now can display only the HTML but not the styling. I use the following to display the HTML:

    HTML Code:
    $('#iframe').contents().find('#display').html(myHtmlCode);
    I know how to update CSS in real time for single elements using something like:

    HTML Code:
    $('#iframe').contents().find('#div-in-display').css('color', 'black');
    I can't use the above one-to-one CSS styling because my HTML code that will be displayed is dynamic.

    Thanks for any ideas.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by nayen View Post
    Thanks for any ideas.
    Can you create and update a <style> section in the head section of the iframed content?
    Last edited by paul_wilkins; Apr 25, 2013 at 19:29.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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