skip to Main Content

I have a html table with rows like this:

<tr class="d-flex linkObj" style="display: flex !important;">
    <th class="col-4">
        <div class="document-icon">
            <i class="far fa-file-code"></i>
        </div>
        <span class="file_data">Tobier - WordPress Tutorials, SEO Tools und vieles mehr<br>
            <span class="analyse_url quelle">https://tobier.de</span>
        </span>
    </th>
    <th class="col-2">
        Bild: https://tobier.de/media/2018/06/logo-4.png
    </th>
    <th class="col-2">
        <i class="far fa-check-circle text-success"></i> follow
    </th>
    <th class="col-4">
        <div class="document-icon">
            <i class="far fa-file-code"></i>
        </div>
        <span class="file_data">https://tobier.de<br>
            <span class="analyse_url ziel">https://tobier.de</span>
        </span>
    </th>
</tr>

i am iterate through all rows and want check the <span class="analyse_url ziel"> value.
so my iterate looks like this:

jQuery('.linkObj').each(function (i, obj) {
    //if span value == 'https://tobier.de' do this:
    obj.style.setProperty("display", "none", "important");
});

all my attempts to access the span from the object failed, can you help me get the content of the spans?

3

Answers


  1. To access the span within the tr, you can use find() within your each(). Then you can perform the check on the text() of that element and call hide() on the tr, like this:

    jQuery(function($) {
      $('.linkObj').each(function() {
        if ($(this).find('span.analyse_url').text() == 'https://tobier.de') {
          $(this).hide();
        }
      });
    });
    

    Note that you can make this slightly more succinct by providing a boolean value to toggle():

    $('.linkObj span.analyse_url').each(function() {
      $(this).toggle($(this).find('span.analyse_url').text() != 'https://tobier.de');
    });
    
    Login or Signup to reply.
  2. $('.linkObj .analyse_url.ziel').each(function (i, obj){
        //if span value == 'https://tobier.de' do this:
        if(obj && (obj.innerHTML == 'https://tobier.de')){
            obj.hide();
        }
    });
    
    Login or Signup to reply.
  3. It is very important that you put the tag TR inside a TABLE otherwise it does not work. And that’s the code.

    $('.linkObj span.analyse_url').each(function(i, element) {
            var obj = $(element);
        if (obj.text() == "https://tobier.de") {
            obj.hide(); // hide the span
          obj.closest(".linkObj").hide(); // hide the entire row
         }
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search