Forums

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

Home Forums CSS [Closed] How to create nonclickable anchor tag? ??

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #46191
    Manojnaanak
    Participant

    Hello everyone,

    How to create nonclickable anchor tag? ??

    #141856
    Manojnaanak
    Participant

    click event should not work. no matter there is link or not

    #141857
    chrisburton
    Participant

    @manojnaanak What are you trying to do exactly (as asked above)?

    #141859
    Manojnaanak
    Participant

    may be i am unable to make you understand due to my poor english.

    actually i want to create a anchor tag that should be non clickable means if click on it i should be stay there.

    may be you understand now.

    :|

    #141860
    pixelgrid
    Participant

    you can do one of the following

    1 – as @Melindrea said dont use an href attribute

    2 – preventDefault with javascript

    3 use another inline element (like a span) and style it

    #141861

    <a class="prevent" href="#">Link</a>

    // Script
    $(".prevent").on("click", function(e){
    e.preventDefault();
    });

    #141862
    chrisburton
    Participant

    @manojnaanak @pixelgrid @adahei

    Instead I would just do the following:

    Text

    Demo: http://codepen.io/chrisburton/pen/trHEL

    #141865
    Manojnaanak
    Participant

    thanking you @Adahei

    #141888

    @chrisburton: That works too but I really dont like to add inline javascript.

    #141967
    gowda24
    Participant

    Hi,

    use the following code to make it non-clickable
    click
    or
    click

    Second one even doesnt trigger the click at all.

    #141968
    gowda24
    Participant
    #141969
    gowda24
    Participant
    #141970
    gowda24
    Participant
    #141973
    Alen
    Participant

    > `click`

    This would jump you to the top of the page.

    If the only thing you are doing is preventing linking I suggest going with inline JavaScript like @chrisburton mentioned. This way it’s very explicit and there’s no need to go back and forth between HTML/JS to figure out what class is targeted with jQuery and whatnot. All you need to know is in one place–HTML. (possibly might need to rethink this approach if you are not template based, if you need to manage many HTML files=nightmare)

    Now if you are adding extra functionality and interactivity it would make more sense to manage all the code in one place, external JS file.

    Hope that helps

    #141999
    jurotek
    Participant

    I am thoroughly confused. OP never explain under what circumstances he wants to implement something as this. So at the end we end up with something that looks like a link which is not suppose to be clickable but is, with no action on click. So what does something like this convey to user. You just want me to click on it for the fun of it? Should I think at that point that you forgot to hyperlink it or you just fooling around? The predictability and user expectations are right out of the window. There is prolly room for something like this, usually active navigation tab but is it in your case?

Viewing 15 posts - 1 through 15 (of 18 total)
  • The topic ‘[Closed] How to create nonclickable anchor tag? ??’ is closed to new replies.