kilp-web@sbcglobal.net Posted January 19, 2010 Share Posted January 19, 2010 I have been looking at a web page that has links of the form "<a href="#">Title</a>".I would appreciate an explanation of what this does.Thanks,Jerry Link to comment Share on other sites More sharing options...
Ingolme Posted January 19, 2010 Share Posted January 19, 2010 The link most likely has some Javascript assigned to it that does something else when you click on it. Link to comment Share on other sites More sharing options...
Charamei Posted January 19, 2010 Share Posted January 19, 2010 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. Link to comment Share on other sites More sharing options...
skaterdav85 Posted January 20, 2010 Share Posted January 20, 2010 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 comment Share on other sites More sharing options...
Ingolme Posted January 20, 2010 Share Posted January 20, 2010 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 comment Share on other sites More sharing options...
skaterdav85 Posted January 20, 2010 Share Posted January 20, 2010 how do you prevent the default action from doing that? Link to comment Share on other sites More sharing options...
Synook Posted January 20, 2010 Share Posted January 20, 2010 By making the JavaScript handler return false, e.g. onclick="return do_something()", where do_something returns false. Link to comment Share on other sites More sharing options...
kilp-web@sbcglobal.net Posted January 20, 2010 Author Share Posted January 20, 2010 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 comment Share on other sites More sharing options...
Synook Posted January 21, 2010 Share Posted January 21, 2010 Are you sure there is no JavaScript? Link to comment Share on other sites More sharing options...
roundcorners Posted January 21, 2010 Share Posted January 21, 2010 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 comment Share on other sites More sharing options...
Ingolme Posted January 21, 2010 Share Posted January 21, 2010 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. Link to comment Share on other sites More sharing options...
skaterdav85 Posted January 21, 2010 Share Posted January 21, 2010 is there a special name for writing JS like this? I'd like to learn more about it. Link to comment Share on other sites More sharing options...
Ingolme Posted January 21, 2010 Share Posted January 21, 2010 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." Link to comment Share on other sites More sharing options...
jeffman Posted January 21, 2010 Share Posted January 21, 2010 is there a special name for writing JS like this? I'd like to learn more about it.Here's some info: http://www.sophox.com/wordpress/?p=106 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.