www.webdeveloper.com
Results 1 to 2 of 2

Thread: Creating and destroying an image (3 questions in one)

  1. #1
    Join Date
    Jul 2010
    Posts
    71

    Question Creating and destroying an image (3 questions in one)

    3 Questions:

    Code:
    document.write("Text");
    ^Displays text. Is there one that will create an image instead of text?

    If so what code can i use to destroy it?

    Can i assign it an id using javascript? (for css)

    Answering any one of these will help

    thanks ZZy

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    HTML Code:
    <SCRIPT type="text/javascript">
    var k=''
     k+='documentWrite any html with tags. ';
     k+='Note how I use single quotes here. ';
     k+='This way, as you normally would write html ';
     k+='with double quotes around attributes, no need to escape them or break your habit.';
     k+='<DIV id="aDiv"><img src="anImage.jpg"> See?</DIV>';
     k+='to destroy the image, only need to set the innerHTML of the div to"" <br>';
     k+='<input type=button onclick="document.getElementById(\'aDiv\').innerHTML=\'\'"" value="imageGoAway"><P>';
     k+='If you over-use this method of innerHTML, some browsers are likely to crash. ';
     k+='You should look up and study <I>DOM Elements Object</I> for the other methods ';
     k+='such as <i>appendChild()</i> and <i>removeChild()</i>'
    
    document.write(k)
    </SCRIPT>

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