my code
function forgotpassword() { $('a').each(function(index, element) { if ($(element).attr("href") == "forgotpassword") { $(element).html("It Worked!"); // Change this to .html() } else { alert('not available'); } }); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
so its generated error
Uncaught SyntaxError: Invalid or unexpected token
and my code don't work
i have to compare anchor href value
to another value
i have also search similar question in stackoverflow
but it different type of code
If you check the error in the console, you can click the line number which causes the error and see the code:
You can see from the red dot that you have an illegal character; that is the source of your problem. Just delete that character and the code works without error:
function forgotpassword() { $('a').each(function(index, element) { if ($(element).attr("href") == "forgotpassword") { $(element).html("It Worked!"); // Change this to .html() } else { alert('not available'); } }); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.