开发者

How to use the jquery .load() function to return the innerHTML of an element

开发者 https://www.devze.com 2022-12-26 15:39 出处:网络
JQuery Assume this works: $(\'table td\').load(\'/my/url/ div p\'); I would end up with <td><p>Some Text</p></td>

JQuery

Assume this works: $('table td').load('/my/url/ div p');

I would end up with <td><p>Some Text</p></td>

I want to end up with 开发者_如何学Go<td>Some Text</td>

How would I do that?


Select all immediate children of the p:

$('table td').load('/my/url/ div p > *');


You probably need to use a callback function. Something like:

$('table td').load('/my/url/ div p', function () {
    $(this).find("p").replaceWith($(this).text());
});


var el = $('table td').load('/my/url/ div p', function() {
    var $this = $(this);
    $this.html($this.find('p').html());
});
0

精彩评论

暂无评论...
验证码 换一张
取 消