开发者

change data received with get()

开发者 https://www.devze.com 2023-03-28 22:09 出处:网络
How can I manipulate html received from the server with get()? var jqxhr = $.get(\"/ajax/get_info\", function(data) {

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();
0

精彩评论

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