Dave's example became more clear when I realized that attr is the name of a jquery function, and he is just caling it from the jquery object via indexing instead of the normal "."
jQuery["attr"]("id") is the same as jQuery.attr("id") where jQuery is any $(...) expression. eval isn't needed here, you want your method to be executed at some time, bind it to a click or just run it inside the chain via each. $('#xyz').callMethod("hide();document.location.href='new url'") might translate into $('#xyz').bind('click',function(){$(this).hide();document.location.href='new url'}) On 1/16/07, Antonio Collins <[EMAIL PROTECTED]> wrote: > I don't quite follow your example: jQuery["attr"]("id") > > I assume this is what you're speaking of: $("#identifier")["attr"]("id") > > If so, is this not equivalent to $("#identifer")["id"]? Also, ["attr"] does > not appear to provide access to methods so it is not a replacement for > object['method-name'].call( object, parm, ... ); > > I realize that .callMethod() could be rewritten as: > jQuery.fn.callMethod = function( method ) > { > try { > return eval("this."+ method ); > } > catch (e) { > return this; > } > } > > But we bar the use of eval() and consider it a security risk (or at least a > wildcard that we don't want to deal with). Using eval() the following could > be executed: $('#xyz').callMethod("hide();document.location.href='new url'") > .callMethod() using the parsing technique at least ensures that any > execution is limited to methods on the current jQuery collection. > > The parameter passing deficiencies could be addressed with a bit morecode, > but for our purposes number conversion is sufficient. > > > -----Original Message----- > From: Dave Methvin [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 16, 2007 5:39 PM > To: 'jQuery Discussion.' > Subject: Re: [jQuery] .callMethod( method ) > > > I don't know if jQuery already has a way to do this (or if anyone else > > would find it useful), but here's a simple extension to call a method > > (with or with > > parameters) via a string. > > Javascript lets you call a method directly with a string: > jQuery["attr"]("id") gets the id for example. Instead of passing a string of > arguments and parsing it you could just eval the attribute in the examples > you gave. Ad-hoc parsing often will get you into trouble; for example the > code you have will not process arglists that have strings with embedded > commas. > > > > > > _______________________________________________ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > -- Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/