Search code examples
jqueryajaxtagsresponsehead

find head tag from ajax response


I searched for this simple topic but i couldn't find anything, sorry. I need to ask you.

I'm getting the sucess response from ajax, only interested in ".someclass" part, as the following code says:

<code>
function TITO(){
    $.ajax({
    url: 'www.tito.com/index.html',
    success:
    function(response){
            $divvy = $(response).find('.someclass');
    $('#finaldiv').html($divvy);
            },
      });
};
</code>

But the thing is that .someclass is a table, and i get it totally unformatted (no styles), just it keeps its structure (table tbody tr th, etc).

What i want is to keeps the original format, and i know that those instructions are on the head tag in the ajaxed index.html (linked css file or specified just there).

How can get the head tag too in my response, and then append $divvy after that, so the table shows styled?

I know to get class (.class) or id (#id) but i don't know how to reach tags without ids or classes :)

Many thanks. gretz, Sergio.


Solution

  • $(response).find('head');
    

    the "find" method from jquery can get as a par a selector like you have you fint ('.someclass"). you used there a css selector for classes with the dot. you can use # for id as you mentioned before and you can use 'nothing' for tags. you can read more about the css selectors: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors .