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

javascript - jQuery get current element (x)html - Stack Overflow

programmeradmin1浏览0评论

I have the next input element:

<input type="text" name="username" id="username" value="user name" 
    helper="formText" defvalue="user name" class="filling" />

How can I get this html by id "username" with help of jQuery?

I try to make it with get(), html(). But I want to get html of current element.

Thank you in advance.

Sorry for my english.

I have the next input element:

<input type="text" name="username" id="username" value="user name" 
    helper="formText" defvalue="user name" class="filling" />

How can I get this html by id "username" with help of jQuery?

I try to make it with get(), html(). But I want to get html of current element.

Thank you in advance.

Sorry for my english.

Share Improve this question edited Aug 25, 2014 at 3:52 chiwangc 3,57716 gold badges27 silver badges32 bronze badges asked Dec 23, 2010 at 10:05 Alex PliutauAlex Pliutau 22k28 gold badges114 silver badges144 bronze badges 1
  • So you want the HTML of the input tag? – lonesomeday Commented Dec 23, 2010 at 10:07
Add a ment  | 

1 Answer 1

Reset to default 6

You can't get the exact HTML (as different browsers handle this differently), but closest you can get is appending a cloned version to a temporary element and taking the .innerHTML of that, like this:

var html = $("<div/>").append($("#username").clone()).html();
发布评论

评论列表(0)

  1. 暂无评论