javascript - JS append </a> to <a> -


i cannot append </a> <a> (the second part isn't linked together) can use concatenation showed below. how solve instead of using concatenation?

<!doctype html> <html> <head>     <meta charset="utf-8">     <title>i'm template</title> </head> <body>     <div id="a"></div>     <script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgfzhoseeamdoygbf13fyquitwlaqgxvsngt4=" crossorigin="anonymous"></script>     <script>         var b = '<a href="#">%data%',             c = ' - %data%</a>',             d = '1';          // concatenation         $("#a").append(b.replace('%data%', d) + c.replace('%data%', d));          $("#a").append('<br>');          // append         $("#a").append(b.replace('%data%', d));         $("#a").append(c.replace('%data%', d));     </script> </body> </html> 

you not need have anchor tag inside variables. can first create anchor tag , append div#a, , append contents of %data% newly created anchor tag

<body> <div id="a"></div> <script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgfzhoseeamdoygbf13fyquitwlaqgxvsngt4=" crossorigin="anonymous"></script> <script>     var b = '%data%',         c = '%data%',         d = '1';      $("#a").append("<a href='#' id='anchortag'></a>");      $("#anchortag").append(b.replace('%data%', d));     $("#anchortag").append(c.replace('%data%', d)); </script> 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -