I am looking to assign a class to a div based on the selected option from a dropdown menu.
<form onsubmit="return creationMessage(this)"
target="_blank"
name="NomForm"
method="post"
action="/posting.forum"
id="am">
<div class="fond">
<div class="faction">Presentation</div>
<select id="ttype" name="ttype" class="obligatoire" focus>
<option>dresseur</option>
<option>ligue</option>
</select>
</div>
</form>
And a simple block
<div class="faction"></div>
If the option "dresseur" is selected, I want this :
<div class="faction dresseur"></div>
I tried:
$('select').on('change', function() {
var colorSelect = $(this).val();
$('.faction').addClass('colorSelect');
});