2

im trying to get the currently selected option in a dropdown menu with javascript. but i cant seem to get it to work

my current js:

var itemqual = $("select#itemqual option:selected").text(); var type = "hat"; $('select#itemtype').change(function() { if(itemtype == type) { $('#graphic').show(); } else { $('#graphic').hide(); } }); 

however when I change the selection it doesnt work.

1 Answer 1

2

This Javascript should work for you.

var type = "hat"; $('select#itemtype').change(function() { if($("select#itemtype option:selected").text() == type) { $('#graphic').show(); } else { $('#graphic').hide(); } }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.