September 8, 2013

multiple selector to include back $(this)?

Merralee Mandel’s Question:

I’m not sure is this possible. Selecting multiple element is easy, but today I doubt whether this is possible or not:

$(this).closest("li, + $(this)").css('text-decoration','line-through');

The above code surely not working. It’s just for the demo of the idea. I want to strike the entire li (text and the checkbox) so I selected the li together with the checkbox.

$(this).closest("li").andSelf().css('text-decoration','line-through');

or

$(this).closest("li").addBack().css('text-decoration','line-through');

for jQuery 1.8 and above

You can use .add() function to add selectors:

$(this).closest("li").add(this).css('text-decoration','line-through');
...

Please fill the form - I will response as fast as I can!