[英]How to add using jquery `a href` for label?
<label for="id_zip_code">
Zip code:
</label>
How to add using jquery a href
for this label? 如何使用jquery
a href
为该标签添加标签?
Excepted output: 排除的输出:
<a href="http://google.com"><label for="id_zip_code">Zip code:</label></a>
尝试
$('label[for="id_zip_code"]').wrap('<a href="http://google.com"><a/>')
尝试
$('label[for=id_zip_code]').wrap($('<a />', {href: "http://google.com"}));
Use wrap()
: 使用
wrap()
:
$('label').wrap($('<a></a>', {
'href': 'http://www.google.com'
});
Obviously, you'd be best to make the label
selector more specific by adding a class or id to the element. 显然,最好通过向元素添加类或ID来使
label
选择器更具体。
<label id="somelable" for="id_zip_code">
Zip code:
</label>
$("#somelable").wrapInner("<a href=http://google.com></a>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.