1

I'd like to hide the <div id="sociallocker"> if the word: email appears in the URL. And show the <div id="emaillocker"> if it does appear.

I've tried the following but no luck:

<script type="text/javascript">
    $(function () {
        if (window.location.href.indexOf("email") != -1) {
            $("#sociallocker").hide();
        }
    });
</script>

HTML

<div id="sociallocker">
    [sociallocker id="1505"] [/sociallocker]
</div>

<div id="emaillocker">[emaillocker] [/emaillocker]
</div>

I am running Wordpress with JQuery & Bootstrap on the Genesis Framework. Not sure if I need to add anything else to the JQuery to get it to fire?

Live test: https://www.moneynest.co.uk/test-page-for-stack/

Sam

Waleed Iqbal
  • 1,308
  • 19
  • 35
Sam Jefferies
  • 584
  • 1
  • 7
  • 27

2 Answers2

0
if(document.location.href.indexOf("email") >= 0) {
// do your thing
}
Cybernetic
  • 12,628
  • 16
  • 93
  • 132
  • No luck, both continue to display see: https://www.moneynest.co.uk/test-page-for-stack/ – Sam Jefferies Mar 24 '18 at 15:12
  • Have you tried using .css(‘display’, ‘none’) instead of .hide()? – Cybernetic Mar 24 '18 at 15:52
  • Changed to: but still no luck. Can't help but feel I'm missing something obvious. How can I check if the script is actually firing? – Sam Jefferies Mar 24 '18 at 16:32
  • I used alert(‘fired’) inside my answer and it fires when the address contains the word “email”. So the code works. I am not housing my answer inside $(function () so try removing that. – Cybernetic Mar 24 '18 at 16:39
  • Hmmm, still no luck. I think Wordpress might be blocking it from loading? – Sam Jefferies Mar 24 '18 at 17:18
  • You may need to change the PHP in a Wordpress file to retrieve the address then. https://stackoverflow.com/a/11246141/1639594 – Cybernetic Mar 24 '18 at 18:21
0

I think this should solve your problem

if (window.location.href.indexOf("email") != -1) {
    $("#sociallocker").hide();
    $("#emaillocker").show();
} else {
    $("#sociallocker").show();
    $("#emaillocker").hide();
}
Waleed Iqbal
  • 1,308
  • 19
  • 35