You could group it together to shorten it. Makes it nicer (for me, at least) and less variables. :)
var cid = this.id.split('_')[1]; On Sep 28, 9:26 pm, lionel28 <lmarte...@haitiwebs.net> wrote: > Hi Charlie. > > In a page I have a lot of entries and I am onclick do an edit. So each one > must have a unique id. > the split allows me to get the id > > $(document).ready(function() { > $('a[id^=doedit_x]').live('click', function(event) { > var fullid = this.id; > var split = fullid.split("_"); > var cid = split[1]; > > $("div#newcomment").slideUp("slow"); > $("div#editcomment_" + cid).show(); > > var options = { > target: '#maintable_' + cid, > success: showResponse > }; > > $('#commentform_' + cid).submit(function() { > $(this).ajaxSubmit(options); > return false; > }); > > > > lionel28 wrote: > > > Charlie, > > > Thank you very much. > > I was able to do a split so I get actual value from your code and all is > > fine. > > > I do whatever I want with php, but could you recommend a book for > > Javascript. > > > Example: for the split I had to do a Google search :thinking: > > > A book with all those easy code like yours, like the split would be great. > > > Thanks again. > > > Charlie Griefer wrote: > > >> You shouldn't need to use a named function, or an inline onclick. > > >> If you can move that id attribute into the tag itself, you could do: > > >> # ... > > >> and then your jQuery would be: > > >> $(document).ready(function() { > >> $('a[id^=doedit_]').click(function() { > >> alert(this.id); <-- shows that you have a handle on the > >> specific > >> element that triggered the click > >> return false; > >> }); > >> }) > > >> On Mon, Sep 28, 2009 at 4:34 AM, lionel28 <lmarte...@haitiwebs.net> > >> wrote: > > >>> Hi, > > >>> I am trying to get the correct div from a form > > >>> I did (I intentionally left the brackets open so it displays here) > >>> span id="doedit_$comment[commentid]"> a onclick= "return > >>> getCommentID($comment[commentid]) > > >>> and for the jQuery > > >>> $(document).ready(function() { > > >>> function getCommentID(cid) > >>> { > > >>> $("#doedit_" + cid).click(function() { > > >>> $("div#newcomment").slideUp("slow"); > >>> $("div#editcomment_" + cid).slideDown("slow"); > > >>> } > >>> }); > > >>> But nothing is happening. > > >>> Please what is the proper syntax? > > >>> Thank you > >>> -- > >>> View this message in context: > >>>http://www.nabble.com/How-to-handle-dynamic-clicks--tp25644199s27240p... > >>> Sent from the jQuery General Discussion mailing list archive at > >>> Nabble.com. > > >> -- > >> Charlie Griefer > >>http://charlie.griefer.com/ > > >> I have failed as much as I have succeeded. But I love my life. I love my > >> wife. And I wish you my kind of success. > > -- > View this message in > context:http://www.nabble.com/How-to-handle-dynamic-clicks--tp25644199s27240p... > Sent from the jQuery General Discussion mailing list archive at Nabble.com.