Question

apply basic j query filter and highlight second and fourth elements with red boarder

apply basic j query filter and highlight second and fourth elements with red boarder

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code that you asked which was done by filter method and it is very basic.

the indexing start from 0 in jquery so we have taken odd positions.

index.html

<!DOCTYPE html>
<html>
<head>
<title>Filtering with jQuery</title>
<style>
.showOdd{
border: 1px solid red;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("ul li").filter(":odd").addClass("showOdd");//selecting odd positions(indexes) such as 1,3,5 so 1 represents 2nd element
$("p").filter(":odd").addClass("showOdd");//selecting odd positions(indexes) such as 1,3,5 so 1 represents 2nd element
});
</script>
</head>
<body>
   <h2>first example with list</h2>
<ul><!--first example with list-->
<li>First list item</li>
<li>Second list item</li>
<li>Third list item</li>
<li>Fourth list item</li>
</ul>
<hr>
<h2>Second Example with 'p' tags</h2>
<!--second example with p elements-->
<p>Welcome 1</p>
<p>Welcome 2</p>
<p>Welcome 3</p>
<p>Welcome 4</p>
</body>
</html>

Output screenshot:

first example with list First list item Press F11 to exit full screen Secod list item Third list item Fourt list item Second

Thanks, hope it helps to you.

Add a comment
Know the answer?
Add Answer to:
apply basic j query filter and highlight second and fourth elements with red boarder
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT