javascript - Getting inner html with jQuery? - Stack Overflow

I have a javascriptjQuery block as a callback after $.get function:function myCallBack(data, textStatu

I have a javascript/jQuery block as a callback after $.get function:

function myCallBack(data, textStatus) {
  var text1 = $(data).html();
  document.write(text1);
} 

The data contains html data ok. I'd like to strip the html and get only inner html into text1 variable. For some reason it doesn't work. Firebug kinda "crashes" upon executing line 'var text1 = ...'

Edited:

My data variable contains:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3/TR/xhtml1/…;\r\n\r\n<html xmlns="w3/1999/xhtml">;\r\n
<head>\r\n 
<title></title>\r\n
</head>\r\n
<body>\r\n Testing...\r\n</body>\r\n
</html>\r\n 

And I'd like to parse the part between body tags.

I have a javascript/jQuery block as a callback after $.get function:

function myCallBack(data, textStatus) {
  var text1 = $(data).html();
  document.write(text1);
} 

The data contains html data ok. I'd like to strip the html and get only inner html into text1 variable. For some reason it doesn't work. Firebug kinda "crashes" upon executing line 'var text1 = ...'

Edited:

My data variable contains:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3/TR/xhtml1/…;\r\n\r\n<html xmlns="w3/1999/xhtml">;\r\n
<head>\r\n 
<title></title>\r\n
</head>\r\n
<body>\r\n Testing...\r\n</body>\r\n
</html>\r\n 

And I'd like to parse the part between body tags.

Share Improve this question edited Jul 6, 2009 at 9:55 Pompair asked Jul 6, 2009 at 9:08 PompairPompair 7,31912 gold badges64 silver badges69 bronze badges 2
  • Did you try innerHTML? – Gumbo Commented Jul 6, 2009 at 9:12
  • Just tried. var text1 = data.innerHTML; Returns "undefined". – Pompair Commented Jul 6, 2009 at 9:59
Add a ment  | 

3 Answers 3

Reset to default 6

You mean you want the inner text?

var text1 = $(data).text();

[Update]

Try it with this regular expression:

var bodyText = new RegExp(/<body[^>]*>([\S\s]*?)<\/body>/).exec(data)[1];

Try this:

$(data)[1].data

But I think that just works with a specific example and not in general.

You perform a webrequest by get. That implies that the result will only be a string.

var text1 = data ;

Is all you can get. There is no DOM-object you can traverse. You only get this if you access elements on you own page.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742300583a4417955.html

相关推荐

  • javascript - Getting inner html with jQuery? - Stack Overflow

    I have a javascriptjQuery block as a callback after $.get function:function myCallBack(data, textStatu

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信