3 Replies - 378 Views - Last Post: 02 September 2011 - 06:18 PM

#1 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 11

How can one call two separate action with the same event in jQuery?

Posted 02 September 2011 - 03:03 AM

Hello all, I recently made the switch from JS to JQ. In JS, it was possible to use a single inline event to call several actions, by merely separating the actions with a semi colon. In JQ, this technique does not work. Here's an example of what I'm talking about.

 onclick = '$(this).parent().next().next().children().eq(0).show(); (this).next().hide();'> 	 



I tried using two onclicks like this:

 onclick = '$(this).parent().next().next().children().eq(0).show();' onclick='$(this).next().hide();'> 	 


but in this case, only the first onclick call works. The second doesn't. So my question is, how can one achieve this if at all possible? I don't want to use functions in the head section because this particular problem requires me to use inline event calls. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: How can one call two separate action with the same event in jQuery?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,250
  • Joined: 08-June 10

Re: How can one call two separate action with the same event in jQuery?

Posted 02 September 2011 - 03:47 AM

you solve that problem by not using event attributes and do it jQuery-like (which btw. still is JS)
// abbreviating the longer expressions
$('someid').click(function(){ 
    $(this).next().hide(); 
}).click(function(){ 
    $(this).prev().show(); 
});

This post has been edited by Dormilich: 02 September 2011 - 03:48 AM

Was This Post Helpful? 0
  • +
  • -

#3 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 11

Re: How can one call two separate action with the same event in jQuery?

Posted 02 September 2011 - 12:06 PM

@ dormilich, i have a very compelling reason why im using inline event attributes and not functions, i don't want to bother anyone with the details. but someone in another forum just pointed out what was wrong. i was missing the $ operator before the second this. fixed that and everything works fine.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: How can one call two separate action with the same event in jQuery?

Posted 02 September 2011 - 06:18 PM

Moved to jQuery. Please post jQuery questions in the right forum!

Good to know you're cross-posting too. We'll think about that before we spend a lot of time answering a question for which you may have already received an answer elsewhere.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1