admin管理员组文章数量:1327466
I make an ajax call from my page , and then in response I also get some html like this
<parent id="1"><child></child></parent>
what I want is to get Inner HTML from the Response object excluding <parent>
How can I do that?
Cant use document.getElementbyID
on a variable.
I make an ajax call from my page , and then in response I also get some html like this
<parent id="1"><child></child></parent>
what I want is to get Inner HTML from the Response object excluding <parent>
How can I do that?
Cant use document.getElementbyID
on a variable.
-
do you want
<child></child>
? – Arun P Johny Commented Oct 15, 2013 at 15:14 - @ArunPJohny Yes exactly.. – user1765876 Commented Oct 15, 2013 at 15:15
3 Answers
Reset to default 9you can create a jQuery wrapper for the variable content and then extract the inner html using .html()
var data = '<parent id="1"><child></child></parent>'
var x = $(data).html()
Pure JS if you like -> http://jsfiddle/eztZm/
//get
var get_html = document.getElementById("parent").innerHTML;
console.log(get_html);
//set
document.getElementById("parent").innerHTML = "new html";
https://developer.mozilla/en-US/docs/Web/API/Element.innerHTML
html code used:
<parent id="1"><child>candy</child></parent>
first approach:
var parent = document.getElementById("1");
var child_text = parent.firstChild.innerHTML;
to make a long story short:
document.getElementById("1").firstChild.innerHTML
will deliver "candy" (without jQuery) :)
本文标签: jqueryGetting InnerHtml from a javascript VariableStack Overflow
版权声明:本文标题:jquery - Getting InnerHtml from a javascript Variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742210992a2433708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论