Or simply... $('ul.actions a').each(function() { this.href += '#somewhere'; });
If you want to ensure that the href does not already have a bookmark attached then you may want to add a test before changing the href... $('ul.actions a').each(function() { if(this.href.indexOf('#') < 0) this.href += '#somewhere'; }); ...or apply a filter before going into the each(). On Nov 19, 10:15 am, James Dempster <[EMAIL PROTECTED]> wrote: > I don't think I full understand where your data is or where it's > coming from. But heres an example from what I can understand. > > $('ul.actions a').each(function() { > var $this = $(this); > $this.attr('href', $this.attr('href') + '#somewhere'); > > }); > > On Nov 18, 8:55 pm, Eric Lanehart <[EMAIL PROTECTED]> wrote: > > > Hello everyone, > > > In advance of my question below I must say that I'm a designer that > > has HTML/CSS down very well, and I can deal with Ruby/PHP in my > > templates to do some pretty basic variable stuff and conditional > > logic. My attempts to pick up Javascript though have always fallen > > pretty short. Tried Jeremy Keith's DOM Scripting book, but got lost > > pretty quick once I tried applying the knowledge. I got introduced to > > jQuery through Klaus Hartl's Tabs plug-in (now apart of jQuery UI), > > which is literally going to change the design process at my company > > quite a bit =) I can't wait for the new version of his Remote plugin. > > I've since picked up Learning jQuery and made it up through Chapter 6, > > but it hasn't answered my question thus far and the next chapter is > > about AJAX (!). The API reference hasn't been of much help either. > > Also looked through quite a few threads here, also couldn't find what > > I'm looking for. > > > So I think my question is probably going to be pretty dumb, which is > > why I gave you all the treatise of an explanation above! I'm trying to > > access the href attribute of elements that match a certain selector, > > grab whatever is there for each matched element, and append a standard > > string to whatever is already there. > > > For example, I want to find every element that matches ul.actions a, > > and append the anchor link #somewhere to the end of each link (as > > specified in the href attribute). The attr method of course doesn't do > > this as it wipes out the contents. I'm sure there must be a way of > > saying add "this" to what's already there, i.e.: > > > attr($this + '#somewhere'); > > > But I can't quite figure out the syntax. I loosely remember this.href > > from DOM Scripting so I tried searching around that, and I think I > > might also need to use the each method? And if there is no built-in > > facility for saying "keep whatever is there", would I maybe have to > > fetch that stuff first assign them to variables, and then go the route > > I started to go above? I'm lost as to what exact combination of these > > things will do the trick though. > > > Help! (and thank you very much for your time)