[ 4 posts ]

Green Wang

  • Username: Q.Wang
  • Joined: Sat Jan 16, 2010 6:30 pm
  • Posts: 44
  • Location: Beijing
  • Twitter: cocowool
  • GitHub: cocowool
  • Gists: cocowool
  • Offline
  • Profile

How to use css selector like jQuery style

Post Posted: Sat Jan 30, 2010 10:36 pm
+0-
i want to bind a event to some a elements, and they has the same classname, so how can i use YUI3 to bind the event to these elements
just like jQuery .find('.classname')
thank u very much
YUI, Why not Use In your project?

Joe Developer

  • Username: JoeDev
  • Joined: Sat May 09, 2009 12:54 am
  • Posts: 73
  • Twitter: joe_developer
  • IRC: unomi
  • Offline
  • Profile

Re: How to use css selector like jQuery style

Post Posted: Sat Jan 30, 2010 11:53 pm
+0-
Y.delegate('containerselector', handlerfunction, 'target selectors');

so for example

Y.delegate('#containerid', myhandler, 'a.classname');

where myhandler could be

var myhandler = function(e){
var clickedOn = e.currentTarget;
alert('are you sure you want to go to ' + clickedOn.get('src'));

};

See these for more info:
http://developer.yahoo.com/yui/3/event/
http://developer.yahoo.com/yui/theater/ ... 2009-sugar
http://www.yuiblog.com/blog/2009/11/13/ ... egation-3/
http://developer.yahoo.com/yui/theater/ ... 009-events

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile

Re: How to use css selector like jQuery style

Post Posted: Tue Feb 02, 2010 9:13 am
+0-
This is incorrect, the delegate method's signature is:
EventHandle delegate ( type , fn , el , spec , context , args* )

Code:
Y.delegate('click', handleFn, '#container', 'a.external');


http://developer.yahoo.com/yui/3/api/YU ... d_delegate

Joe Developer

  • Username: JoeDev
  • Joined: Sat May 09, 2009 12:54 am
  • Posts: 73
  • Twitter: joe_developer
  • IRC: unomi
  • Offline
  • Profile

Re: How to use css selector like jQuery style

Post Posted: Tue Feb 02, 2010 9:52 am
+0-
Quite so, apologies
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum