I have a script that loops through a list of DOM elements and manipulates each as it finds them. The problem I am running into is that I need to search two different divs for the same elements.
This is what I have so far
var elements = {
1 : "h1",
2 : "h2",
3 : "h3",
4 : "h4",
5 : "p",
6 : "li",
7 : "a",
8 : "td",
9 : "span",
10 : "img"
}
$.each(elements, function(key, val){
if(val != "img") {
if($(".t_content " + val + ":not([id^=element])"))
$(".t_content " + val + "[id^=element]").addClass('t_element');
} else {
$('.t_content, .t_component').find('img, div > img').addClass('t_element edit_img_area').removeClass('yellow');
$(val).unwrap('a');
}
});
The div I am searching currently is $(".t_content") but I want to search .t_content and .t_component… I know you can search like this $(".t_content, .t_component") but I don’t know how to incorporate that into this script.
Thanks for the help!
Why don’t you do something like this:
You can pass a second argument (context) to $() in jQuery which tells it to look within the context for the items you have in your selector. In your case, your second argument will be the two divs you want to search within:
$(".t_content, .t_component").