Liu, Xiao-Guang (OSLO-R&D-China) schrieb:
> Hi,
> suppose to implement the effect as:
>
> ($("input.c1") OR $("a#c2")).click(function(){ alert("Same effect"); });
> ......
> <input type="button" value="Save" class="c1" />
> ......
> <a href="#" id="c2"> Add </a>
>
>
> That means when clicking button c1 or hyperlink c2, the action will be
> the same.
>
> How to write the jQuery code in correct syntax to do that?
>
>
> Jack
Hi, Jack, simply group you selections just as if you were writing CSS.
If you are not familiar with CSS, there's the possibility to group
selections via a comma separated list.
Try this:
$("input.c1, #c2").click(function() {
alert("Same effect");
});
One more tip: For class selectors I would add a type whenever possible
("div.whatever") to improve performance, but not for an id selector
('#whatever').
In the first case the element type narrows down the scope jQuery has to
search in, in the second case it's the other way round.
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/