On Feb 8, 3:10 pm, "Smith, Allex" <[EMAIL PROTECTED]> wrote: > Any time you do a: > > <a href="javascript:function()">link</a> > > You are looking for the click event. > > So bind to the click event with jQuery: > > $('a').click(function(){ > // at this point when you click on the link it is going to fire > // this anonymous function, you still need a way to get the data > to pass > // as arguments for the load function. I usually handle this > with the metadata > // plugin, however you could easily place the data in the id > attr, style attr or > // a combination of the two. > $('div#target').load('somepage.html', {v1 : var1, .... }); } > // keep the browser from doing its default action > return false; > > > > });
Hi, Smith: thank you so much for your detailed instruction. so I guess 'class' might be the one of the safest attributes to deliver these arguments, right? :-) Regards, lihao(XC) > -----Original Message----- > From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On > > Behalf Of [EMAIL PROTECTED] > Sent: Friday, February 08, 2008 11:20 AM > To: jQuery (English) > Subject: [jQuery] Re: Is it possible to send javascript vars TO a jquery > function?? > > On Feb 8, 1:02 pm, "Smith, Allex" <[EMAIL PROTECTED]> wrote: > > True. But in order to get a link like this: > > <a href="javascript:doSomething('1234','john');>Click me</a> > > > Something has to generat the '1234' and 'john' > > > $('a') is going to iterate over each anchor link and assign the click > > event. > > > One rule of thumb I like to follow for myself however is that is > > something is easy to do without jQuery, or any other library, stick to > > > good old JavaScript. > > > By the way... I always try and stay away from the evil > > 'javascript:function()' syntax... Degrades poorly. > > Hi, Smith, > > The plugin, Metadata, is very interesting and looks very nice.. just > another question: is there any replacement for the > 'javascript:function()' links besides using outside plugins, in ways of > either Javascript or jQuery? > > I usually use javascript psudo links in making some AJAX calls, > something like > > <div id="target"></div> > <a href="javascript:myfunc('a','b')">AB</a> > <a href="javascript:myfunc('c','d')">CD</a> > ............. > > function myfunc(var1, var2) > { > $('div#target').load('somepage.html', {v1 : var1, .... }); } > > which works pretty well so far, but since it degrades poorly, I do want > to find a better way(or replacement) to achieve this.. > > Many thanks. :) > lihao(XC) > > > -----Original Message----- > > From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] > > On > > > Behalf Of cbmtrx > > Sent: Friday, February 08, 2008 9:40 AM > > To: jQuery (English) > > Subject: [jQuery] Re: Is it possible to send javascript vars TO a > > jquery function?? > > > Hmm, so there's no other way to pass vars to a jquery function? This > > also seems a tad long-winded. > > > It would be nice to take advantage of jquery's functionality, without > > sacrificing efficiency! Especially for pages that are generated > > dynamically (where class names and ids are not necessarily known). > > > All the same, thanks for the info. > > > On Feb 8, 11:44 am, "Smith, Allex" <[EMAIL PROTECTED]> wrote: > > > I'm not positive if this will be helpful, but you could try > > > something like this using the Metadata > > > plugin.http://plugins.jquery.com/project/metadata > > > > Your example: > > > <a href="javascript:doSomething('1234','john');>Click me</a> > > > > Could be written like this: > > > > // html > > > <a href="actionPage.html" class="{linkId:1234, > > > linkName:'john'}">Click > > > > me</a> > > > > // javascript > > > // you will need a click event > > > $('a').click(function(){ > > > // using metadata plugin... snag yo data in the class attr > > > var data = $(this).metadata(); > > > // yo... 'doSomething' > > > doSomething(data.linkId,data.linkName); > > > > }); > > > > As always... Totally untested and unapproved :) > > > > -----Original Message----- > > > From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] > > > On > > > > Behalf Of cbmtrx > > > Sent: Friday, February 08, 2008 8:12 AM > > > To: jQuery (English) > > > Subject: [jQuery] Is it possible to send javascript vars TO a jquery > > > > function?? > > > > I've just barely started getting my feet wet with jquery, so please > > > bear with this novice's question... > > > > With a javascript function you can accept vars like this: > > > > function doSomething(number, name) { > > > //Do something with them > > > } > > > > From an href in the HTML like this: > > > <a href="javascript:doSomething('1234','john');>Click me</a> > > > > But I have no idea how this is accomplished with jquery as it all > > > seems "internal" to itself (seemingly dealing only with identifying > > > HTML tags, ids, and classes, and not user-supplied vars). I'm sure > > > I'm > > > > wrong on this... > > > > I had started to build out a page that will be using multiple show/ > > > hide toggles for individual divs/ids and the jquery examples I was > > > finding all seemed more long-winded than just using my original > > > javascript function, so I'm hoping that this would considerably > > > simplify the process, but, more importantly, keep it native to > > > jquery's functions. > > > > Any suggestions?- Hide quoted text - > > - Show quoted text -