i want to add link to label tag the code is this:
<div class="swatchinput">
<label selectid="pa_color" class="attribute_pa_color_black wcvaswatchlabel wcvasquare"</label>
<div>
how i can add <a href="test.com">
then close that with after </label>
to make link.
i use this code with jquery but dosnt work fine
$(".swatchinput").before( "<a href='https://yenial.ir'>" );
$( "</a>" ).appendTo( ".attribute_pa_color_black" );
答案 0 :(得分:1)
看起来你不明白HTML,DOM,jQuery是如何工作的。你需要知道的是:
<a></label></a>
,这就是你所要求的我相信的。)$("</a>")
这样的选择器。任何以/
开头的标记都是结尾标记。<label>
<a>
<label>
的起始标记。href
属性。<a>
内<label>
或反之亦然。你仍然可以继续做你想做的事,但浏览器会推出它。因此,考虑到以上几点,您需要的是:
$(".swatchinput").wrapInner( "<a href='https://yenial.ir'>" ); // Or
$(".swatchinput").append( "<a href='https://yenial.ir'>" );
工作代码段
$(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>
但是当上面的代码运行时(将<a>
附加到<label>
),浏览器会这样做: