change data received with get()
How can I manipulate html received from the server with get()?
var jqxhr = $.get("/ajax/get_info", function(data) {
// here I want开发者_如何学C to change the data
$.colorbox({html:function(){
return data;
}});
});
When using Jquery selectors it ignores the html data received, unless I append it to the DOM first. I want to change the data before passing it to Colorbox. How can I do that?
As you say, just... change the data before you pass it to colorbox:
$.get("/ajax/get_info", function(data) {
data = transform(data);
$.colorbox({html:function(){
return data;
}});
});
If you want to perform DOM manipulations on an arbitrary HTML string:
var data = /* whatever */,
$data = $(data),
$divs = $data.find('div');
// etc
do whatever you want to do with data. This removes all a tags
data.find('a').remove();
精彩评论