Reputation: 923
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
Upvotes: 0
Views: 601
Reputation: 20260
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');
Upvotes: 1
Reputation: 6646
try
txtWord = $('.top').text().split('text')[1]
if(txtWord){
alert("div show");
}else{
alert("div hide");
}
Upvotes: 1
Reputation: 1434
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';
}
}
Upvotes: 0
Reputation: 74420
var lastWord = function (o) {
return ("" + o).replace(/[\s-]+$/, '').split(/[\s-]/).pop();
};
if (lastWord($('.top').html()) === "mykeyword") {
$('.middle,.bottom').hide();
} else $('.middle,.bottom').show();
Upvotes: 0
Reputation: 863
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();
}
Upvotes: 0
Reputation: 2206
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();
}
Upvotes: 0