html - how to check the div value in javascript -


how set div css styles using javascript? have problem getting value of class name. please if know it.

<div class="this_is_i_want_to_set_the_background_color" id="divname"></div> <div class="test" id="divname"></div>  var classname = $('.divname').attr('class'); var t = 'divalue'; if(classname == t){     $('.divname').css('background', '#0962ae'); } 

you may use .hasclass method:

$('.divname').each(function() {     if ($(this).hasclass('divalue')) {         $(this).css('background', '#0962ae');     } }); 

but there 1 simpler way this:

// element class 'divname' has class 'divalue' $('.divname.divalue').css('background', '#0962ae'); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -