What is the difference between parent(), parents() and closest() in jQuery?
<div class="box"><ul><li><span id="s">x</span></li></ul></div>
console.log($('#s').parent().prop('tagName'));
console.log($('#s').parents().length);
console.log($('#s').closest('.box').prop('tagName'));
Console output
LI
5
DIV
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |