2

I am trying to add a class to a variable inside one of my if else statements in a jquery function. I am getting an error x.addclass is not a function. I have tried placing the variable in () and without. It makes no difference.

var ideal = document.getElementById( 'ideal_' + id )
var Search = document.getElementById('Search_' + id)

var parent = document.getElementById(+id)
if(ideal){
    parent.addClass('myclass')
}  else if (Search){
   parent.style.background='yellow'
}  else {
   parent.style.background='none'
} 
user14955679
  • 171
  • 7

1 Answers1

2

.addClass() is a jQuery method, you can call that on a jQuery referenced element.

Try using classList.add():

parent.classList.add('myclass');
Mamun
  • 58,653
  • 9
  • 33
  • 46