I have a web-page on which I am using jQuery to access the value of a select element. When the element has an “empty” value (the value = ""), I want to hide a link elsewhere on the page. Unfortunately – I can’t seem to get it working.
Here is my current code:
$(document).ready(function(e) {
if ($('#cancelNumber').select().val() == "") {
$('#ticketsLink').hide();
} else {
$('#ticketsLink').show();
}
});
The div tags each have a unique ID (already checked for that) – and I have also tried using === insetad of == – but that didn’t work either. What am I doing wrong?
Your call to
.select()is just going to fire theselectevent on the#cancelNumberelement. I think what you’re looking for is more akin to: