0
$(document.getElementById("item1"), document.getElementById("item2")).click(function () {
    $(this).fadeOut();
});



<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.

https://jsfiddle.net/p3uofsru/1/

Edited by pritaeas: Moved to web dev.

2
Contributors
2
Replies
17
Views
1 Year
Discussion Span
Last Post by RikTelner
0

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});

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.