Right, but I was saying was, INSTEAD of modifying my HTML markup to prevent the default event (using return false, javascript:;, etc), I could simply loop through all the links on the page from the <head> and set preventDefault() on them in that manner, that way when I need to make the prototype functional, I can just remove that jQuery routine and all is back to normal.
Am I not making any sense? On 2/16/07, Yehuda Katz <[EMAIL PROTECTED]> wrote:
Kenneth: Again, if you use return false, you don't need preventDefault(). -- Yehuda On 2/16/07, Kenneth < [EMAIL PROTECTED]> wrote: > > Yes, good points everyone and I stand corrected. > > I don't advocate inline JS, however I do produce > mock-up/prototype/concept pages pretty frequently (not meant for public use > or distribution) where I need to show functionally how an element will > behave. In these cases, its easiest for me to simply use href="javascript:;" > as it produces the intended result yet has no side-effects, and it lets us > click the links but doesn't take us out of the prototype (and the only > reason that's necessary is because IE doesn't treat <a>'s as links unless > they have an href attribute [no :hover, text-decoration, etc]). > > I didn't think about it until now, but I suppose an easier method would > be to use jQuery to preventDefault() on all of the <a>'s in my prototypes? > > > On 2/16/07, Yehuda Katz <[EMAIL PROTECTED]> wrote: > > > > Yes yes yes! > > > > Just a quick note: you can use "return false" perfectly fine in > > jQuery. In fact, it'll work for all browsers, even if it doesn't normally > > work exactly right. You can use preventDefault() as well, if you just want > > to stop the default action but not stopPropagation (return false in jQuery > > blocks the default action and prevents further propagation). > > > > -- Yehuda > > > > On 2/16/07, Tim Baxter < [EMAIL PROTECTED]> wrote: > > > > > > No... you don't put the onclick handler on the link either. Keep > > > your JS out of your HTML. > > > > > > If it's a link that's ONLY there for the JS to do something, insert > > > the link with the JS. > > > If it's a link that can degrade gracefully (the preferred scenario), > > > then put the link in, then override it's action. > > > > > > Whether the link is a full link, an anchor link, or just a dummy # > > > link, return false (or, in jquery, preventDefault();) will prevent it from > > > scrolling or otherwise causing you trouble. > > > > > > This is basic unobtrusive scripting. > > > > > > > > > On 2/16/07, Kenneth < [EMAIL PROTECTED]> wrote: > > > > > > > > I actually prefer javascript:; since using # usually scrolls the > > > > page to the top which can be really annoying. If it's not a real link I > > > > don't see what the problem is there. > > > > > > > > Now, if it's an actual link that you're wanting to apply an > > > > onclick function to, you should use the onclick="javascript:return > > > > myfunc();" attribute, use the normal URL in the href="", and then return > > > > true/false from myfunc() depending on whether or not you want to link to be > > > > activated by the click. > > > > > > > > On 2/16/07, hcabbos <[EMAIL PROTECTED] > wrote: > > > > > > > > > > What's the best way to apply a behavior to an anchor tag? > > > > > > > > > > <a href="#" class="someClass">my text</a> > > > > > > > > > > -- or -- > > > > > > > > > > <a href="javascript:;" class="someClass">my text</a> > > > > > > > > > > _______________________________________________ > > > > > jQuery mailing list > > > > > [email protected] > > > > > http://jquery.com/discuss/ > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > jQuery mailing list > > > > [email protected] > > > > http://jquery.com/discuss/ > > > > > > > > > > > > > > _______________________________________________ > > > jQuery mailing list > > > [email protected] > > > http://jquery.com/discuss/ > > > > > > > > > > > > -- > > Yehuda Katz > > Web Developer | Wycats Designs > > (ph) 718.877.1325 > > _______________________________________________ > > jQuery mailing list > > [email protected] > > http://jquery.com/discuss/ > > > > > > _______________________________________________ > jQuery mailing list > [email protected] > http://jquery.com/discuss/ > > -- Yehuda Katz Web Developer | Wycats Designs (ph) 718.877.1325 _______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
_______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
