SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamically setting display property reloads the window

    Hi all:

    I am currently encountering a problem with setting "display" property from "none" to "block":

    browsers will refresh itself when the display property is changed; this causes the element to display then suddenly disappear after the page reload. Do you guys have an idea what I can do to avoid it?

    I tried using jquery's show command, css command with setting display to block, and pure javascript method like document.getElementById("theId").style.display="block".

  2. #2
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW, in IE9, the page reload even results in redirecting to the index page.

  3. #3
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NVM guys, i figured it out.

    Do not add href attribute to the element where you want to change the display property, cuz it will cause the browser to reload.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,683
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by philwei View Post
    NVM guys, i figured it out.

    Do not add href attribute to the element where you want to change the display property, cuz it will cause the browser to reload.
    That occurs because the web browser is performing the default behaviour for that element.

    Normally you can prevent that default behaviour by returning false from the function that handles the onclick event.
    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
  •