Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: Adding a class to an element that has no ID

Is there a way to add a class to an element (using pure javascript) that does not have an ID, but has some existing classes? If I had:

<div class="rightAlign pushDown">...</div>

How could I add a class to make it like this

 <div class="rightAlign pushDown redOutline">...</div>

This is just a simple example. The reason for adding another class and not changing the original class in CSS or changing the class altogether with javascript is that I am dealing with elements created by Dojo. I just need to access something that has no convenient ID to grab a hold of.

Keep in mind I am working in javascript and Dojo, I can not use jQuery at all...

like image 901
user2219915 Avatar asked Dec 05 '25 03:12

user2219915


1 Answers

The dojo way would be as:

dojo.query(".rightAlign.pushDown").addClass("redOutline");

This will add the class to add elements with those two classes

like image 149
tik27 Avatar answered Dec 06 '25 17:12

tik27