Why all elements turn red? I only intend to turn <p> red.
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ul>
<p>a paragraph</p>
<script>
$('li').add('p').css('background-color', 'red');
</script>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$('li')is selection all the li$('li').add('p')is adding p tag into selected all theli$('li').add('p').css('background-color', 'red')is changingall the li and pbackgroundColor to red.from jQuery.add API