Thursday, 15 July 2010

html - Display image from directory using jQuery? -


I am currently learning the basics of web development, but there is one thing I have not found any solution yet. Image from a directory using if I have the checkbox defined as ...

  & lt; Input id = "check" type = "checkbox" & gt;  

... How can I get an image from a directory and it depends on the current status of the checkbox by and lt; Div & gt; Can I show in HTML with messing? This is what I've found so far, but it's a & lt; Div & gt; to show the current content, right?

  $ (document) (work () ($ ('# check'). Click (function () {if (!! ($!) (.: (': Check I do not want to touch HTML so that I understand the more powerful functions of jQuery. I want to understand more deeply (I do not want to make bad habits), but it is proving to be a difficult task for me. I really appreciate any help (or just some hint)!  

tl; dr: check box S = image, uncheck = no image due to JQuery due to reasons only

You can ( Div is present) exists

  $ (document) .ready (function () {// div to reference which later var $ div = $ ('div'), $ img ; $ ('# Check') can be used again. Change (function () check the check box // Check the display position of the div based on the status $ div.toggle (this.checked); if ( This.checked) {// If it is checked and img is not currently making a (! $ Img) {$ img = $ ('& lt; img / & gt;', {src: '//placehold.it/64/00ff00'}). AppendTo ($ div);}}});});  

Demo:


No comments:

Post a Comment