SxChoc SxChoc - 4 months ago 10
HTML Question

Remove class from next element jQuery

I've got a this html:

<div class="results">
<div class="resultitem" page="1">
<div class="col-sm-12 odd">
<div class="col-sm-2 noLRPadding"><p class="memFName">Arsene</p></div>
<div class="col-sm-2 noLRPadding"><p class="memLName">Wenger</p></div>
<div class="col-sm-3 noLRPadding"><p class="memEmail">louise.lockie@wilmingtonplc.com</p></div>
<div class="col-sm-1 noLRPadding"><p class="memLevel">Affiliate</p></div>
<div class="col-sm-1 noLRPadding"><p class="memCPD">0</p></div>
<div class="col-sm-1 noLRPadding"><p class="memTarCPD">10</p></div>
<div class="col-sm-1 hidden noLRPadding"><p class="memDiff">10</p></div>
<div class="col-sm-1 noLRPadding"><p><a class="memLink" href="/my-membership/cpd-centre/cpd-log/?m=CON-000184210">View</a></p></div>
<div class="col-sm-1 noLRPadding text-center"><a class="showConfirm" href="#" data-user="CON-000184210" data-username="Arsene Wenger"><i style="font-size: 18px; color: #b43e91" class="fa fa-times-circle"></i></a></div>
</div>
<div class="logPanel hidden">
<p>Hello</p>
</div>
</div>
<div class="resultitem" page="1">
<div class="col-sm-12 odd">
<div class="col-sm-2 noLRPadding"><p class="memFName">Jack</p></div>
<div class="col-sm-2 noLRPadding"><p class="memLName">Wilshire</p></div>
<div class="col-sm-3 noLRPadding"><p class="memEmail">louise.lockie@wilmingtonplc.com</p></div>
<div class="col-sm-1 noLRPadding"><p class="memLevel">Affiliate</p></div>
<div class="col-sm-1 noLRPadding"><p class="memCPD">0</p></div>
<div class="col-sm-1 noLRPadding"><p class="memTarCPD">10</p></div>
<div class="col-sm-1 hidden noLRPadding"><p class="memDiff">10</p></div>
<div class="col-sm-1 noLRPadding"><p><a class="memLink" href="/my-membership/cpd-centre/cpd-log/?m=CON-000184209">View</a></p></div>
<div class="col-sm-1 noLRPadding text-center"><a class="showConfirm" href="#" data-user="CON-000184209" data-username="Jack Wilshire"><i style="font-size: 18px; color: #b43e91" class="fa fa-times-circle"></i></a></div>
</div>
<div class="logPanel hidden">
<p>Hello</p>
</div>
</div>


And what I'm trying to do is show the 'hiddden' logPanel div when the memLink link is pressed so in script I've got:

$(".results").on("click", ".memLink", function (e) {
e.preventDefault();
$(this).nextAll('.logPanel').first().removeClass('hidden');
alert("hello");
});


but tweak as I might I can't get this to work. Could some =one shed any light please?

Thanks,
Craig

Answer

find closest class "resultitem", and then find required first element.

    $(this).closest(".resultitem").find(".logPanel:first").removeClass('hidden');
Comments