最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - append div tag Into anchor tag using jquery? - Stack Overflow

programmeradmin5浏览0评论

Greeting..

In Browser Html is

<div tabIndex="0" title="People Picker" class="ms-inputuserfield">Administrator</div> 

i want to replacewith look like

<a href='#'> <div tabIndex="0" title="People Picker" class="ms-inputuserfield">Administrator</div></a>

i tried to so much for make this. not succeed yet. plz Help me.

i try by this code :

 var list = $("<a href='#' />");
 $(list).wrapInner($('#maindiv').html())
 $('div.ms-inputuserfield').replaceWith(list);

i knew that i am going wrong way.its replace by anchor.

Greeting..

In Browser Html is

<div tabIndex="0" title="People Picker" class="ms-inputuserfield">Administrator</div> 

i want to replacewith look like

<a href='#'> <div tabIndex="0" title="People Picker" class="ms-inputuserfield">Administrator</div></a>

i tried to so much for make this. not succeed yet. plz Help me.

i try by this code :

 var list = $("<a href='#' />");
 $(list).wrapInner($('#maindiv').html())
 $('div.ms-inputuserfield').replaceWith(list);

i knew that i am going wrong way.its replace by anchor.

Share Improve this question edited Feb 17, 2012 at 9:55 Jignesh Rajput asked Feb 17, 2012 at 9:46 Jignesh RajputJignesh Rajput 3,55832 silver badges50 bronze badges 3
  • Ok might want to post some code, explain more what you are trying to do. – Dejan.S Commented Feb 17, 2012 at 9:48
  • In any case this is invalid HTML. The anchor element may only contain other inline elements. – cillierscharl Commented Feb 17, 2012 at 9:50
  • @Dejan i did edit my question. – Jignesh Rajput Commented Feb 17, 2012 at 9:56
Add a ment  | 

2 Answers 2

Reset to default 4

you could do

$('div.ms-inputuserfield').wrap('<a href="#"/>');

EDIT - fiddle here http://jsfiddle/QUcux/

If it's not working, remeber that you must put it in document.ready()

$(document).ready(function(){
    $('div.ms-inputuserfield').wrap('<a href="#"/>');
});

Use the jQuery wrap method.

$('div.ms-inputuserfield').wrap('<a href="#" />');

http://api.jquery./wrap/

Thanks

发布评论

评论列表(0)

  1. 暂无评论