valerio massacci
valerio massacci

Reputation: 39

if a span contain a specific text add a display:none;

$(document).ready(function(){
    $('.views-field-nothing').click(function(){
        $(this).parent().find('.comments-toggle').slideToggle("fast");
        $('.comments-toggle:contains('Anonimo')').css("display", "none");    
    });   
});

at first it must show the comment field clicking on View-field-nothing (slideToggle) then if it find "Anonimo" it should replace the slideToggle -> Display:block; with a Display:none..

<div class="views-row">
    <div class="views-field-nothing">
        <span class="field-content">
            <span class="comments">COMMENTI</span>
        </span>
    </div>
    <div class="views-field-name">
        <span class="field-content">
            <span class="comments-toggle">Anonimo</span>
        </span>
    </div>
</div> 

<div class="views-row">
    <div class="views-field-nothing">
        <span class="field-content">
            <span class="comments">COMMENTI</span>
        </span>
    </div>
    <div class="views-field-name">
        <span class="field-content">
            <span class="comments-toggle">Utente A</span>
        </span>
    </div>
</div> 

once you click the second "Commenti" that is is in the "view-field-nothing" div the function .slideToggle() must write a display:block; in the html, like down here

 <div class="views-row">
   <div class="views-field-nothing">
      <span class="field-content">
          <span class="comments">COMMENTI</span>
      </span>
 </div>
 <div class="views-field-name">
    <span class="field-content">
        <span class="comments-toggle">Anonimo</span>
    </span>
 </div>
</div> 

<div class="views-row">
 <div class="views-field-nothing">
     <span class="field-content">
         <span class="comments">COMMENTI</span>
     </span>
</div>
<div class="views-field-name">
    <span class="field-content">
        <span class="comments-toggle" display:block;>Utente A</span>
     </span>
 </div>
</div> 

if i click the first "COMMENTI" it should find the "Anonimo" string in the span and write at the end of the span a display:none;

 <div class="views-row">
   <div class="views-field-nothing">
      <span class="field-content">
          <span class="comments">COMMENTI</span>
      </span>
 </div>
 <div class="views-field-name">
    <span class="field-content">
        <span class="comments-toggle" style="display:none;">Anonimo</span>
    </span>
 </div>
</div> 

<div class="views-row">
 <div class="views-field-nothing">
     <span class="field-content">
         <span class="comments">COMMENTI</span>
     </span>
</div>
<div class="views-field-name">
    <span class="field-content">
        <span class="comments-toggle" style="display:block;">Utente A</span>
     </span>
 </div>
</div> 

Upvotes: 2

Views: 7246

Answers (2)

CAbbott
CAbbott

Reputation: 8098

EDIT: Here's an updated script based on your updated question. It is possible to hide all the Anonimo spans initially and then check for using the slide animations on those that don't contain the Anonimo:

$(document).ready(function(){
    $(".comments-toggle:contains('Anonimo')").hide();
    $('.views-field-nothing').click(function(){
        var field = $(this).siblings('.views-field-name').find('.comments-toggle');
        if (field.text() != 'Anonimo')
            field.slideToggle("fast");
    });   
});

Here's the modified jsFiddle: http://jsfiddle.net/3mbMA/6/

Upvotes: 1

boobiq
boobiq

Reputation: 3004

you have to use double quotes " or escape single quote \', if you are already in open brackets

$(".comments-toggle:contains('Anonimo')").css("display", "none");    

Upvotes: 0

Related Questions