Hide RSS feed if specific text is included

I pull RSS feeds using the following code:

<div id="mcdougaldteens"> <script src="http://feeds.feedburner.com/dcl_mcdougald_teen?format=sigpro" type="text/javascript" ></script> </div> 

This is a feed of upcoming events, and if there are no events that appear in the channel: "The channel providing these headers is unavailable."

I either want him to change the text to “No more events,” or just to completely hide the feed if the channel does not pull events.

I tried something like this without success:

 <script type="text/javascript"> function hideEmptyRSS() { var el = document.getElementById("mcdougaldteens"); if(el.innerHTML == "The feed providing these headlines is not available.") { el.style.display = "none"; } else { el.style.display = "block"; } } </script> 

I could use JavaScript, PHP or CSS. Any help would be appreciated.

+4
source share
1 answer

you missed indexOf on line 3:

 function hideEmptyRSS() { var el = document.getElementById("mcdougaldteens"); if (el.innerHTML.indexOf("The feed providing these headlines is not available") > -1) { el.style.display = "none"; } else { el.style.display = "block"; } } 

EDIT

ok, I just saw the script create another div inside yours.
so you need to look for text in a new element, but hide yours. eg:

 var el_mine = document.getElementById("mcdougaldteens"); var el_theirs = document.getElementsByClassName('feedburnerFeedBlock'); if (el_theirs[0].innerHTML.indexOf("The feed providing these headlines is not available") > -1) { el_mine.style.display = "none"; } else { el_mine.style.display = "block"; } 

check here: http://jsfiddle.net/RASG/DqrT9/

+3
source

Source: https://habr.com/ru/post/1438760/


All Articles