views:

50

answers:

1

My code:

<a href="#" onclick="$('#s input[name='reset']').click(); return false;">RESET</a>

Apparently as you can see I can't use ' nor " at the part [name= as either one will end the previous quotation mark of the same type.

Need some help. One way would be to define a function and have onclick trigger the function, but I'm hoping to get the code (it's just 1 line) assigned to onclick.

+4  A: 

Well, you could use escaped \' or \" but the best solution at all is just not to use those inline event handlers.

$('a').bind('click', function(e){
   $('input[name=reset]').trigger('click');
});

Obviously, this would affect all anchors. So a class or an ID would be advisable.

jAndy
Alright thanks. I figured out almost as soon as I posted, and I'm (pleasantly) surprised to see 3 answers already. :D
Fabian
BTW what's the difference between using the `bind()` and `click(function() {});`? And why `function(e)`? Why not other letters?
Fabian
there is no difference, `click()` is a shortcut for `.bind('click',..)` philosophical question :)
jAndy
btw, your accept rate is way too low :p
jAndy
Wanted to set your answer as accepted answer just now, but I had to wait 1 hour :)
Fabian