0

i want to hide some elements after a specific text / the last word of the first div

<div class="top">here is some text</div>
<table class="middle">
...
</table>
<div class="bottom">...</div>

hide table(middle) and the div(bottom) depending on the word "text" from the first div

Jim
  • 923
  • 4
  • 17
  • 30

6 Answers6

1

You can get the last word using: $('.top').text().split(' ').pop(), and then add some simple logic to show/hide the other elements:

var lastWord = $('.top').text().split(' ').pop();
$('.middle, .bottom').toggle(lastWord == 'text');
billyonecan
  • 20,090
  • 8
  • 42
  • 64
1

try

http://jsfiddle.net/EnQym/1/

txtWord = $('.top').text().split('text')[1]
if(txtWord){
alert("div show");
}else{

alert("div hide");
}
ShibinRagh
  • 6,530
  • 4
  • 35
  • 57
0

Example if in your .top div text is hide or show the function must be:

var txt = $('.top').text();

if(txt=='hide')
{
   $('.middle').hide();
   $('.bottom').hide();
}
else if(txt=='show')
{
   $('.middle').show();
   $('.bottom').show();
}
edonbajrami
  • 2,196
  • 24
  • 34
0

If you need to check the text of the first div and show the relative div



    if($(".top").html() == "what you want")
    {
        $(".middle").show();
        $(".bottom").hide();
    }
    else
    {
        $(".bottom").show();
        $(".middle").hide();
    }

Emanuele Pavanello
  • 785
  • 1
  • 9
  • 22
0
var lastWord = function (o) {
    return ("" + o).replace(/[\s-]+$/, '').split(/[\s-]/).pop();
};

if (lastWord($('.top').html()) === "mykeyword") {
    $('.middle,.bottom').hide();
} else $('.middle,.bottom').show();
A. Wolff
  • 74,033
  • 9
  • 94
  • 155
0

lets have a method you call

hideOrShow(){
if(document.getElementsByClassName('top')[0].innerHtml=="the text you want"){
document.getElementsByClassName('middle')[0].style.display='none';
document.getElementsByClassName('bottom')[0].style.display='none';
}else{
document.getElementsByClassName('middle')[0].style.display='block';
document.getElementsByClassName('bottom')[0].style.display='block';
}
}
Muhammad Bekette
  • 1,396
  • 1
  • 24
  • 60