jquery - add <a> tag into a class with javascript -


i want add link label tag code this:

    <div class="swatchinput">        <label selectid="pa_color" class="attribute_pa_color_black wcvaswatchlabel wcvasquare"</label>      <div> 

how can add <a href="test.com"> close after </label> make link. use code jquery dosnt work fine

 $(".swatchinput").before( "<a href='https://yenial.ir'>" );       $( "</a>" ).appendto( ".attribute_pa_color_black" );  

looks don't understand how html, dom, jquery works. need know is:

  1. you cannot have improper nesting (like <a></label></a>, asking believe).
  2. there no selector $("</a>"). tag starting / ending tag.
  3. you cannot wrap <label> <a>.
  4. you haven't closed <label>'s starting tag correctly.
  5. you haven't closed href attribute correctly.
  6. you cannot have <a> inside <label> or vice-versa.

still may continue wanna do, browser push out. so, considering above points, need is:

$(".swatchinput").wrapinner( "<a href='https://yenial.ir'>" ); // or $(".swatchinput").append( "<a href='https://yenial.ir'>" ); 

working snippet

$(function () {    $(".swatchinput").append( "<a href='https://yenial.ir'>" );  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="swatchinput">    <label selectid="pa_color" class="attribute_pa_color_black wcvaswatchlabel wcvasquare"></label>  </div>

but when above code run (append <a> <label>), browser makes way:

preview


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 -