1

I'm a little new to jQuery, and i'm in need of being able to parse a document that contains a news feed in the following structure (sorry for the poor format, not great at getting code to show properly here). Can anyone lend a hand? I need to be able to grab the image, news title, and the snippet of news information.

<div class="article-list">
 <ul>
  <li>
  <div class="image-container">
  <img src="" /></div>
  <div class="content-container">

  <h3>News Title</h3>
  <p>News Information</p>
  <p><a href="#">More</a></p>
</div>
</li>

<li>
<div class="image-container">
<img src="" /></div>
<div class="content-container">

<h3>News Title</h3>
    <p>News Information</p>
    <p><a href="#">More</a></p>
   </div>
  </li>

  <li>
   <div class="image-container">
<img src="" /></div>
   <div class="content-container">

<h3>News Title</h3>
    <p>News Information</p>
    <p><a href="#">More</a></p>
   </div>
  </li>
 </ul>
</div>

o

1
  • is it something wrong with answers? Commented May 15, 2012 at 17:04

2 Answers 2

2

It's easy:

var myHtml = "... some valid HTML  ... "
var parsed = $(myHtml);

var images = parsed.find('img'); // or some more specific selector....
Sign up to request clarification or add additional context in comments.

Comments

0
$(function() {
  var news_title = $('li h3').html();
  var article_img = $('li img').html();
  var news_snippet = $('li h3 + p').html();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.