Gaylord.P
Gaylord.P

Reputation: 1468

Find Html element in ajax responseText

With AJAX and jQuery 3.3.1 I have this response :

var responseText =
  <tr>
    <td>
      Lavender
    </td>
  </tr>
  <tr>
    <td>
      Lime
    </td>
  </tr>
  <div class="navigation mt-3 text-center" id="ajax-navigation">
    Test
  </div>

I want to extract #ajax-navigation div.

$(responseText).find('#ajax-navigation').html() = undefined
$(responseText).filter('#ajax-navigation').html() = undefined
$($.parseHTML(responseText)).find('#ajax-navigation').html() = undefined
$($.parseHTML(responseText)).filter('#ajax-navigation').html() = undefined

Can you help me? I've already read this question and this one too

Upvotes: 0

Views: 750

Answers (1)

Pankaj Vishwani
Pankaj Vishwani

Reputation: 342

You can do something like the following:

var node = document.createElement("div");
node.innerHTML = responseText;
var navigationNode = $("#ajax-navigation", node);
var navigationHTML = navigationNode.html();

This should work without changing your responseText

Upvotes: 1

Related Questions