- This topic is empty.
-
AuthorPosts
-
July 8, 2013 at 1:04 am #46191
Manojnaanak
ParticipantHello everyone,
How to create nonclickable anchor tag? ??
July 8, 2013 at 1:29 am #141856Manojnaanak
Participantclick event should not work. no matter there is link or not
July 8, 2013 at 1:32 am #141857chrisburton
Participant@manojnaanak What are you trying to do exactly (as asked above)?
July 8, 2013 at 1:39 am #141859Manojnaanak
Participantmay 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.
:|
July 8, 2013 at 1:44 am #141860pixelgrid
Participantyou 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
July 8, 2013 at 1:48 am #141861Historical Forums User
Participant
<a class="prevent" href="#">Link</a>
// Script
$(".prevent").on("click", function(e){
e.preventDefault();
});
July 8, 2013 at 1:50 am #141862chrisburton
Participant@manojnaanak @pixelgrid @adahei
Instead I would just do the following:
July 8, 2013 at 2:21 am #141865Manojnaanak
Participantthanking you @Adahei
July 8, 2013 at 7:41 am #141888Historical Forums User
Participant@chrisburton: That works too but I really dont like to add inline javascript.
July 8, 2013 at 11:16 pm #141967gowda24
ParticipantJuly 8, 2013 at 11:18 pm #141968gowda24
ParticipantJuly 8, 2013 at 11:20 pm #141969July 8, 2013 at 11:20 pm #141970July 8, 2013 at 11:54 pm #141973Alen
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
July 9, 2013 at 10:24 am #141999jurotek
ParticipantI 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?
-
AuthorPosts
- The topic ‘[Closed] How to create nonclickable anchor tag? ??’ is closed to new replies.