admin管理员组文章数量:1356232
Why doesn't the following code work?
var err = document.getElementById("text-error").value;
if (err == "Team already exists") {
$('#text-error').fadeIn(400).delay(3200).fadeOut(800);
}
The error does not fade in or fade out.
Checked the console - no problems.
Also, this particular error is sent via the server.
The fade in and fade out work for my client side errors - but not errors pertaining to my database like this one - if that makes any difference to the problem.
UPDATE
After console logging - I realize that it does not enter the if statement, even though it clearly equals it - via html code and via a quick glance at the page.
Why doesn't the following code work?
var err = document.getElementById("text-error").value;
if (err == "Team already exists") {
$('#text-error').fadeIn(400).delay(3200).fadeOut(800);
}
The error does not fade in or fade out.
Checked the console - no problems.
Also, this particular error is sent via the server.
The fade in and fade out work for my client side errors - but not errors pertaining to my database like this one - if that makes any difference to the problem.
UPDATE
After console logging - I realize that it does not enter the if statement, even though it clearly equals it - via html code and via a quick glance at the page.
Share Improve this question edited Dec 25, 2012 at 3:42 JoseBazBaz asked Dec 25, 2012 at 3:26 JoseBazBazJoseBazBaz 1,4454 gold badges15 silver badges23 bronze badges 2- 2 What is it doing and what should it do instead? Some context would be nice. – Blender Commented Dec 25, 2012 at 3:27
- I'm like brand new to JS - so I assumed it would be some silly error that I was not aware of - I have now added more details. – JoseBazBaz Commented Dec 25, 2012 at 3:36
2 Answers
Reset to default 2I am assuming you have something like
<div id="text-error> Team already exists </div>
If so, then replace your first line of code with
var err = document.getElementById("text-error").innerText;
JsFiddle - http://jsfiddle/fCNe8/
Try :
var err = $("#text-error").val();
if (err == "Team already exists") {
console.log('is equal but problem is fadeing not working');
$('#text-error').fadeIn(400).delay(3200).fadeOut(800);
}else {
console.log('not equal');
}
but ofcourse more details about the issue will help us
本文标签: JavaScriptif id equals somethingStack Overflow
版权声明:本文标题:JavaScript - if #id equals something - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744010132a2575411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论