English 中文(简体)
HTML get get
原标题:Get HTML of div element returned by .get with jQuery

I m 试图通过植被要求(植被要求、带有3个不同孩子的3个半个圆点的回归超文本数据)获得特定微粒的超文本。

我的守则如下:

$.get("ajax/learn-more.html", function(data){
    var $response = $(data);
    alert($response.find( #main-images )); // <= prints [Object object]
    alert("Data Loaded: " + data); // <= displaysthe whole html of learn-more.html
    // how can I get the html of a div in learn-more.html with id="main-images" ???
});

EDIT:

The content of learn-more.html:

<div id="something" class="hero-unit span-one-third" style="position: relative;">
    Foo Bar
</div>

<div id="main-images" class="hero-unit span-one-third" style="position: relative;">
    <div id="learn-more-photo" class="span-one-third">
        <img class="thumbnail" src="http://placehold.it/300x180" alt="">
    </div>
</div>

<div id="learn-more">
:D
</div>
最佳回答

。 j object物。 没有一个选定元素的后代有IDmain-images/code>。 相反,选定内容之一。 你们正在寻求。

To get the a reference to the div use .filter() [docs] instead :

$response.filter( #main-images );

如果你希望获得超文本,首先将内容贴在空<代码>div上,删除不想要的内容:

var container = $( <div /> ).html(data);
container.children().not( #main-images ).remove();
var html = container.html();

或使用outer/2006/2 plugin:

var html = $response.filter( #main-images ).outerHTML();
问题回答

。 www.un.org/Depts/DGACM/index_french.htm 页: 1

如Felix Kling回答,你可以使用<条码>过滤<>/条码>而不是<条码>。

$(data).filter( #main-images ).html();




相关问题
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.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签