Jump to content

Recommended Posts

It returns to the top of the current page (the equivalent of pressing the Home key). A lot of developers use it to generate placeholder links - when coding, it doesn't matter where the links go, just that they are there and you can see how you're styling them.

Edited by Charamei
Link to post
Share on other sites

if you're going to use JS on a dead link, its better to just use CSS to create an object w/ link like features (using the cursor: pointer css property). Otherwise it jumps to the top of the page, unless this is what you want. I actually just recently discovered this :)

Link to post
Share on other sites
if you're going to use JS on a dead link, its better to just use CSS to create an object w/ link like features (using the cursor: pointer css property). Otherwise it jumps to the top of the page, unless this is what you want. I actually just recently discovered this :)
If you prevent the default action from occuring then it won't jump to the top of the screen when you use a Javascript event handler on it.
Link to post
Share on other sites

By making the JavaScript handler return false, e.g. onclick="return do_something()", where do_something returns false.

Link to post
Share on other sites

Thanks for all of the help. In this particular case the <a> tag is part of the following code sequence:<li class="class1"><h3>Select your item</h3><ul class="class2"><li class="class3"><a href="#">First Item</a></li><li><a href="#">Second Item</a></li></ul>.....</li>The effect of selecting one of these links it to make one of two divs appear, each of which is effectively a menu.Since there seems to be no JavaSript associated with either tag, I am trying to figure out how the switch between divs occurs.The first one has the following form:<div id="one" class="class4" style="display: block">The second one is similar but has no style attribute. I have been assuming that somehow the "style" attributes were being changed from "display: block" to "display: none", but I don't understand what might be doing this.Jerry

Link to post
Share on other sites

In what context did you find this code?The author may be using :focus to change the position property or display property and so create a non-JS type lightbox effect. However, in that context, the anchor element is unnecessary and shouldn't be used. It's what you might call an Anorexic Anchor. It would make more sense if the # where a reference to a fragment within the document.

Link to post
Share on other sites

Event handlers can be assigned to links without having to edit the link HTML in any way. It's actually the cleaner and better way to work. It's always best to have your scripts interfere as little as possible with the HTML of the page.If there's a script file on that document, you might find something like this:

var i;var links = document.getElementById("menu").getElementsByTagName("a");for(i = 0; i < links.length; i++) {  links[i].addEventListener("click",doSomething,false);}

** This is just a simple example. Internet Explorer uses attachEvent() rather than addEventListener.

Edited by Ingolme
Link to post
Share on other sites
is there a special name for writing JS like this? I'd like to learn more about it.
Not really, it's called "Separating content from behaviour."In the same way that proper CSS is "Separating content from presentation." Edited by Ingolme
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...