English 中文(简体)
排外法
原标题:Parse HTML with jquery
  • 时间:2011-08-18 08:01:32
  •  标签:
  • jquery

假设在变数的html中,则像拯救一样。

var vhtm="<div><div id= test >zebra</div><div id= foo >here is my many other html content</div></div>";

i want to parse the above html stored in variable with the help of jquery. i need to extract a particular div by id and including its content. the return result would like

<div id= foo >here is my many other html content</div>

因此,需要找到象id一样的 d。

请帮助我如何把上述内容如 j。

最佳回答

引言

var divHtml = $(vhtm).find("#foo").html();
问题回答

试图这样做:

$(vhtml).find( #foo );

由于你想要把产出包含整个四部分,包括内容一(d)建议你使用一些定期表述: 与此类似:

var vhtm="<div><div id= test >zebra</div><div id= foo >here is my many other html content</div></div>";
var regex = /<div id= foo >.*?</div>/;
alert(vhtm.match(regex));

结果:

“entergraph

我不知道这样做的任何 way。 我将将此列为OM要素的超文本内容($ (document.createElement( div )]html(vhtm).find(#foo ),或创设一个about:blank iframe, Add the RUS to it and use $ (iframe.contentWindow.document. . . . .find(......),条件是它要求与你因某种原因重新管理文字的网页相隔绝。

应:

http://jsfiddle.net/HenryGarle/Vpa3q/

var vhtml="<div><div id= test >zebra</div><div id= foo >here is my many other html content</div></div>";

var foo = $(vhtml).find( #foo ).html();

alert(foo);




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签