Jacob Seen
Jacob Seen

Reputation: 65

JavaScript - Remove class after img title matches?

So I am trying to do something like. I have an multiple HTML "li's" and each has in <img title=TextHere>. So I would like to match that title part with string what I got. If it matches, then remove parent.parent class name. Here's the HTML

<li class="col 2 zoomIn animated" style="padding: 8px; font-weight: bold; font-size: 16px; animation-delay: 0s;">
   <div class="card item-card waves-effect waves-light" data-itemnaaaaaaaaaaaame="★ Butterfly Knife | Crimson Web (Field-Tested)" style="margin: 0%; min-height: 295px; width: 245.438px; border-radius: 15px; height: 245px;" id="2761454276">
      <div class="iteam" style="text-decoration: underline;text-align: left">Butterfly Knife | Crimson Web</div>
      <div class="condition" style="text-align: left;text-size:13px">Field Tested</div>
      <div class="center-align" style="padding:6%">
         <img title="★ Butterfly Knife | Crimson Web (Field-Tested)" draggable="false" src="https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpovbSsLQJf0ebcZThQ6tCvq4iSqODxMajum25V4dB8xLjD9tjwjgK1_kZoYT30ctKVegM7NFyGrwK5yee90ZDt6ZmazHNluCQ8pSGKMl3kzfs/200fx200">
         <div class="" 'floatvalue'="">
            Float: 0.11503319442272186
            <div class="bitskinscomp" style="font-weight: normal;font-size:12px">BitSkins Price: $111.43 (You save: $-38.15)</div>
            <div class="buyer-price center-align">$149.58</div>
         </div>
      </div>
   </div>
</li>

Full part where is that code in:

$(document).ready(function(){
$('.sweet-content').on('click', 'div', function() {
    var removedname = $(this).ignore('span').text();
    console.log(removedname);
    $('li img[title="' + removedname  + '"]').closest('.card').removeClass('red lighten-1 white-text selected-item');
    $(this).remove();
}); 
});

Upvotes: 1

Views: 94

Answers (2)

Gerard
Gerard

Reputation: 15796

The following will only affect the last one:

var title = "anything";
$("li img[title='" + title + "']").closest("className").remove("className");

Upvotes: 0

Ibrahim Khan
Ibrahim Khan

Reputation: 20750

Try like following

var title = "TextHere";
$('li img[title="' + title  + '"]').parent().parent().removeClass('class_name')

Upvotes: 2

Related Questions