Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Show a hidden DIV with URL parameter

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #263233
    Kognak
    Participant

    Hi,

    I’ve a DIV which is hidden (display:none). I would like to show it when there’s a specific parameter in the URL. I found several tutorials, but never exactly my problem and I’ve 0 skills in javascript.

    I’ve only a DIV with a CLASS, no ID.

    Here’s the codepen :
    https://codepen.io/Kognak/pen/POVwGW

    It’s an example, but on the real website I can’t change the HTML, so not able to set an ID somewhere.

    Thank you for your help !

    #263234
    Shikkediel
    Participant

    The search method will return an integer, so it won’t ever be true. You’d probably want to do something like this:

    if (url.search('show=true') >= 0) {
    

    codepen.io/anon/pen/YEBXea

    You’ll notice I’ve used “boomerang” to match something in the url, you can see the full path with the line that’s commented out.

    #263258
    Kognak
    Participant

    Hi,

    thanks for your help. I didn’t manage to use your code.

    I found another way (I don’t know if it’s the best, but it works) :

    if (window.location.search.indexOf('show') > -1) {
        jQuery('.showhid').css({"display":"block"});
    }
    else {}
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.