4
For organization and performance I usually use several selectors together to perform a jquery method. For example:
$("#bola, #casa, #arvore").css("background-color", "blue");
In this example it works because the selector is a string.
But when using objects I don’t know how to make this join.
New scenario:
var bola = $("#bola");
var casa = $("#casa");
var arvore = $("#arvore");
$(bola, casa, arvore).css("background-color", "blue");
In this case only the bottom of "ball" is painted.
Or by concatenating with a comma:
$(bola+ ","+ casa + "," + arvore).css("background-color", "blue");
In this case neither is painted, as was expected.
So I was wondering if there’s any way to put these objects together by comma or in any way that stay on the same dial.
Test fiddle: http://jsfiddle.net/nsMw3/
NOTE: It is not worth putting that var items = $("#ball, #house"), because I use objects that are brought much more complex, and define them one by one.
+1 The good of the method
add
is that it preserves the stack: http://jsfiddle.net/nsMw3/2/– mgibsonbr
Killer solution! + 1
– Guilherme Oderdenge
In case id does not need to pass as var, only the node element ID and there is no need to pass INDEX position, so you cannot repeat ID’s and it is dispensable to pass the index.
– Ronny Amarante
@abfurlan this array solution with the [0] I think is the maximum that can be reached in terms of readability, organization and performance. Thank you!
– Joao Paulo
@Joaopaulo cool, tb now discovered this way of doing and found interesting post, whenever I needed used with add
– abfurlan