I just play with some basic jQuery and something weird is happening. I have two elements on the page: h1 heading and general link. When I click the link, I would like the text to change to “This text has now changed” and this happens, but then either the button disappears, or a new h1 is created with the same text “this text has not been changed”, or the button itself turns into h1. I'm not sure, but here is my code:
HTML:
<html> <head> <title></title> <link rel="stylesheet" type="text/css" href="css/main.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script src="js/main.js"></script> </head> <body> <h1>This element should change.<h1> <a href="#" class="myLink">Click Me</a><br> </body> </html>
JQUERY:
$(document).ready(function() { $(".myLink").click(function() {
Image Before Clicking:

Image after:

Also, when I added the fading method, everything disappears again, and not just the target element "h1".
Any advice is welcome, as always. Thanks.
user3635683
source share