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

Home Forums JavaScript href opens a div on screen

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #185279

    Hi guys,

    I have a page with a link, that I want that everytime a user clicks on it – it opens a div with content on it.
    How do I do this using CSS ?
    Is it more recommended to do this using JS?



    Javascript would the the optimal solution and it’s a very simple thing to do.

    One thing though, unless you need an actual link to the div, you shouldn’t use an href

    If all the thing does is open a div on the same page, use a button styled how you like.


    you are right about the href thing.
    That’s why I used: “preventDefault”
    using jQuery.

    Here is a JSfiddle with a code I made as an example.
    Maybe my post will help somebody else :)


    I think what Paulie is suggesting is to not use an anchor at all. You can attach a click event to any element. In your case I’d probably use a <span>.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.