0

When I console.log(data) from my ajax callback, it returns the entire html file which includes scripts, css etc which breaks my page. How can I get only the element block which I need? I only need the data within .container.

Jack Guy
  • 8,346
  • 8
  • 55
  • 86
Jennifer
  • 905
  • 9
  • 20

3 Answers3

0

I would do this using regular expressions.

For example, if you wanted to get the content of all .container elements, you could try this regexp:

<[^>]+class="container"[^>]*>([^<]+)<\/[^>]+>

and then collect the captured groups.

See working example on Regex101.com.

Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
0

I think easiest way is to use jquery load function. There is possibility to take only fragment of loaded page.

http://api.jquery.com/load/

Brzochod
  • 1
  • 2
0

Easiest way would be append in hidden tag. Then search for using $(".container") it will return the whole div and you can get html . Here is script code that can help you (use jquery library)

var b= $(".container");
console.log(b[0].outerHTML);

PLEASE CHECK THIS BELOW FIDDLE

http://jsfiddle.net/oyvv9nL0/