Im currently using a script (that is working) where I can apply a certain class to a div, based on the class of another div. I would prefer to use content:contains(), to determine the class of the other div, but when I use it, it applies every class at the same time, from every if statement. The code im using is below.
// Set Olympic
if($(".reg-status.olympic span").hasClass("open")) {
$(".reg-status-view.olympic").addClass("open");
}
if($(".reg-status.olympic span").hasClass("waiting")) {
$(".reg-status-view.olympic").addClass("waiting");
}
if($(".reg-status.olympic span").hasClass("closed")) {
$(".reg-status-view.olympic").addClass("closed");
}
// Set Long Course
if($(".reg-status.long-course span").hasClass("open")) {
$(".reg-status-view.long-course").addClass("open");
}
if($(".reg-status.long-course span").hasClass("waiting")) {
$(".reg-status-view.long-course").addClass("waiting");
}
if($(".reg-status.long-course span").hasClass("closed")) {
$(".reg-status-view.long-course").addClass("closed");
}
Question 1: Is there a cleaner way to do what im current trying
Question 2: How do I .addClass from content with the initial div, as appose to the class on the initial div.
Any help would be appreciated.
First of all, put the searches into a reference variable to prevent re-searching the dom. second, if the source div only contains “open”,”closed”,”waiting” classes, you can copy the class attribute to the target div.