0
<label for="id_zip_code">
      Zip code:
</label>

How to add using jquery a href for this label?

Excepted output:

<a href="http://google.com"><label for="id_zip_code">Zip code:</label></a>
4

4 回答 4

2

Try

$('label[for="id_zip_code"]').wrap('<a href="http://google.com"><a/>')
于 2013-08-14T14:10:15.277 回答
1

try

$('label[for=id_zip_code]').wrap($('<a />', {href: "http://google.com"}));
于 2013-08-14T14:11:22.617 回答
1

Use 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.

于 2013-08-14T14:11:47.127 回答
0

Use wrapInner

<label id="somelable" for="id_zip_code">
      Zip code:
</label>


$("#somelable").wrapInner("<a href=http://google.com></a>");

WORKING DEMO

于 2013-08-14T14:15:08.597 回答