I want to check if two values are meaningfully equal using javascript but it is not working when a button is clicked. Below is my attempt
jQuery(document).ready(function(){
jQuery(':button').click(function () {
if (this.id == 'click') {
alert('this button was clicked');
$('input[type=text]').blur(function(){
$(this).val($.trim($(this).val()));
});//trim white spaces
var name = localStorage.getItem("inputName");
if(document.getElementById('inputName').value === name ){
alert('both values are equal'); //but it never gets executed when the two values are equal
}else {
alert('not showing anything'); //always executing this line
}
}else {
}
});
});
how can I execute the if block only when the two values are equal.
jQuery(':button')is not valid. Did you meanjQuery('button')?===is used to check if something is identical, not necessarily meaningfully equal.==instead of===?console.log(document.getElementById('inputName').value, name);