I want to dynamically add class for this selected class.
HTML :
<select name="number" id="paragraphSpaceOPtion">
<option class="option-1" value="00">00</option>
<option class="option-2" value="05">05</option>
<option class="option-3" value="07">07</option>
<option class="option-4" value="10">10</option>
<option class="option-5" value="15">15</option>
<option class="option-6" value="20">20</option>
</select>
Here is a content I wan't to add class:
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus, in!</p>
</div>
JS :
$(document).ready(function(){
var e = document.getElementById("paragraphSpaceOPtion");
var strUser = e.options[e.selectedIndex].value;
//console.log("option number " + strUser);
//var masud = typeof(strUser);
//console.log(masud);
if(strUser == "00"){
$(".content").addClass("option-no-00");
}
if(strUser == "05"){
$(".content").addClass("option-no-05");
}
if(strUser == "07"){
$(".content").addClass("option-no-07");
}
if(strUser == "10"){
$(".content").addClass("option-no-10");
}
if(strUser == "15"){
$(".content").addClass("option-no-15");
}
if(strUser == "20"){
$(".content").addClass("option-no-20");
}
})
I wan't to dynamically add class name when I select option.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…