SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onClick display none

    How do I use javascript or jQuery to display:none on a background image, onClick only.

    Thank you

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If the element that has the background image has an id of 'theElem' then the JavaScript to make the background image disappear when that element is clicked would be

    Code:
    document.getElementById('theElem').onclick = function() {document.getElementById('theElem').style.backgroundImage = 'none';};
    If the element is identified some other way them you'd use that in place of the id.

    If you want the entire element to be removed from the page you'd substitute display for backgroundImage
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello felgall, that worked great, however, I didn't take into consideration tabbing through the fields would not work. It only works onclick, is there another command that would work with both tabbing and clicking in a field?

    Thank you

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,825
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The keyboard equivalent to clicking the mouse button is to tab to the field and then press the enter key. Just tabbing to the field triggers an onfocus event.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, that worked better. It worked for onclick and onfocus.


Tags for this Thread

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
  •