0

In my application I read an RSS feed. Using zrssfeed (http://www.zazar.net/developers/jquery/zrssfeed/) the elements of the feed are displayed. My problem is that inside each list item, there are three

elements without ID or class.

I want to style each of these

elements differently. How can I achieve this?

<div>
 <ul> 
 <li>
         <img />
         <p>text1</p>
         <p>text2</p>
         <p>text3</p>
 </li>
 <li> .. next item... </li>
 </ul>
</div>

How can I achieve assigning a different ID to each of these elements?

1 Answer 1

2
// after elements have been created
$('li').find('p').each(function (i) {
    $(this).attr('id', 'p_' + i);
});

Fiddle

You could also use css3's nth-child selectors:

p:nth-child(1) {
    color: pink;
}

p:nth-child(2) {
    color: green;
}

p:nth-child(3) {
    color: yellow;
}

Fiddle

Sign up to request clarification or add additional context in comments.

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.