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:
- you cannot have improper nesting (like
<a></label></a>
, asking believe). - there no selector
$("</a>")
. tag starting/
ending tag. - you cannot wrap
<label>
<a>
. - you haven't closed
<label>
's starting tag correctly. - you haven't closed
href
attribute correctly. - 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:
Comments
Post a Comment