Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery parse ajax response data and get element id - value

Tags:

jquery

ajax

I have a jQuery ajax get that will return an html text. From this one I need to extract the h3 element (with id='title') value: THIS IS TITLE.

Can I achieve this with jQuery?

<div class="content">
   <h3 id="title">THIS IS TITLE</h3>
   .....
</div>

and here is the call:

  $.ajax({
      url: url,
      type: 'GET',
      cache:false,
      success: function (data) { // data is the html text returned

       alert('The title is: ' + TITLE HERE);

      }
  });
like image 779
David Dury Avatar asked Jul 24 '14 06:07

David Dury


1 Answers

Use find() method to get the value like below,

$(data).find('#title').text()

An Example for how to use find is here How to Use find()

like image 103
Anto king Avatar answered Sep 18 '22 02:09

Anto king