Reputation: 5169
I've got a select list which is attached to some anchors lower down the page. That all works fine. However it triggers on the first list item which I don't want. Even though it's unlikely someone will go back to the first option, I'd like to remove any errors from the console.
<select name="select-product" id="select-dropdown">
<option value="nothingselected">Select summit fool</option>
<option value="#p-1">Something here</option>
<option value="#p-2">Something here</option>
<option value="#p-3">Something here</option>
</select>
jQuery:
$(document).ready(function () {
$('#select-dropdown').change( function () {
var targetPosition = $($(this).val()).offset().top;
if ($(this).val() =! "nothingselected"){
console.log("not equal to select a product");
$('html,body').animate({ scrollTop: targetPosition}, 'slow');
if ($('html,body').scrollTop() == 0){
$('html,body').scrollTop(0);
console.log("reset");
}
}
});
});
However for the if statement where I'm trying to do something like... If this value is NOT equal to this, then do this. I get an error of:
ReferenceError: invalid assignment left-hand side
I've got a feeling it's to do with my use of .val()
maybe? Would love to solve this with some help please.
Upvotes: 0
Views: 7024
Reputation: 6062
$(this).val() != "nothingselected")
your not equal to is ill formed, try the above
Upvotes: 3
Reputation: 4636
Use the following instead:
if ($(this).val() != "nothingselected"){
Upvotes: 3