$(document.getElementById("item1"), document.getElementById("item2")).click(function () {

<span id="item1">This is item 1</span><br /> <span id="item2">This is item 2</span>

span#item1 { color: red; }
span#item2 { color: green; }

span#item1 is affected. span#item2 not, that means I made mistake in syntax. Is there a way to get it to work. I know exact IDs for items that I want to affect.


Recommended Answers

All 2 Replies

Why on earth are you using document.getElementById and jQuery at the same time???
To locate an element in jQuery just use:
$('#item1').click(function() {//code}); // for an ID
$('.item1').click(function() {//code}); // for an class

To apply a click to multiple elements you can do this
$('#item1, #item2').click(function() {//code}); or$('#item1').add('#item2').click(function() {//code});

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.