I’m trying to use jquery to fade out a <p> tag within a <li> when a delete button is selected.
<ul>
<li>
<p>Here is some text!</p>
<span class="delete">Delete</span>
<li>
<ul>
Here is my jQuery so far:
$(".delete").click(function(){
//Needs to select the <p> tag within the same <li>
$("p").fadeOut();
});
With your structure as quoted, simply:
If it’s possible the
pwon’t be the immediate predecessor to the delete link, then you can do this:…which will fade out all
pelements it finds in theli, or this:…which will fade out the first
pelement it finds in theli, or this:…which will fade out the first sibling it finds working backward from the delete link.
References:
prev– find the immediate previous sibling, or nothing if it doesn’t match the selectorclosest– find the nearest ancestor matching a selectorfind– find all descendants matching a selectorprevAll– find all previous siblings matching a selector, in reverse document order (e.g., working backward from the current element)first– only grab the first element in the current set