Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getElementById won't on particular page (no idea why)

    Second time typing this thanks to this website redirect mid type.

    I am a Javascript coder just trying to make another userscript to remove an irritating feature on my weebly blog.

    For some reason I cannot get a handle to the element.

    here is a simple test code.

    I put in interval to constantly check and I get "not exists", but it does exist. I never have trouble normally and have published many scripts on greasyfork.

    [Javascript]

    var box = document.getElementById('menuBarDiv');


    function HideBox(){

    if (box != undefined && box != null){

    alert('exists');
    box.style.display='none';
    }else{
    alert('Not exists');
    }
    }


    window.setInterval(HideBox, 3000);

    [/Javascript]

    It's a .php, that which the url never changes (not sure how it works) When you are editing the site, you click on a button to go to different page by using nav bar and the url won't change (Some PHP quirkiness)

    Not sure how to go about this..

    Any Idea?

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Use CSS - that's what it's there for

  • #3
    New to the CF scene
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You cannot use CSS alone for this. I need to use a script to inject this CSS everytime the page loads the element. (Weebly scripted the box into place) I want to remove it as soon as it is loaded.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,581
    Thanks
    23
    Thanked 643 Times in 642 Posts
    Welcome to the forums ricci07,
    I love saying this "JS without HTML is worthless".
    But I bet you have more than one thing with the same id.

    Your posted JS wont work.
    This line:
    box.style.display='none

    S/B
    box.style.display='none';



    This does work:
    Code:
    <body>
    <div id="menuBarDiv"></div>
    
    <script type='text/javascript' src='javascript/jquery.js'></script>
    <script type="text/javascript">
    var box = document.getElementById('menuBarDiv');
    
    function HideBox(){
    	if (box != undefined && box != null){
    		alert('exists');
    		box.style.display='none';
    	}else{
    		alert('Not exists');
    	}
    }
    
    
    window.setInterval(HideBox, 3000);
    </script>
    
    </body>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Search the weebly forums. of course you can use CSS.

  • #6
    New to the CF scene
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't think you understand.

  • #7
    New to the CF scene
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No need for html, I am writing in tampermonkey, maybe you are unfamiliar with userscripts. Also, I didn't forget the closing quote and semicolon, this is pretty basic stuff.

    Here is my release userscripts for example of userscripts

    https://greasyfork.org/users/3139-riccardo-geraci

    Maybe try one of them and see how it works.

    try "YouTube Channel Video Searcher" https://greasyfork.org/scripts/4650-...video-searcher, I use no HTML, I use entirely Javascript to create elements and and get elements

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,581
    Thanks
    23
    Thanked 643 Times in 642 Posts
    I think I need a picture of bill the cat to put here.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #9
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    1 if it's your blog, why are you doing this with a user script? that will only make the changes come into effect on computers with the script installed. ie, yours but nobody else's. Using CSS will hide the element BEFORE it exists, no need to be calling a function every 3 seconds.

    2 I know it's possible to do this on a weebly site because I did it last week, getting rid of an ugly footer. possibly you are not targeting the element correctly

  • #10
    New to the CF scene
    Join Date
    Sep 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't want to share this script. It's for me. No one else will seen the annoyance I have. When I click on "custom embed code" when editing the site. This horrible box pops up in front of my code and blocks my view of it. If I move this box the code disapears. If I click on the code area again the stupid box is back covering my code.

    Screenshot

  • #11
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Ahhhhhh, now this is starting to make sense. you could try setting the box's style.visibility="hidden" but still I suspect that you are not targeting the element correctly and that this is a job for css

  • #12
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,436
    Thanks
    13
    Thanked 360 Times in 356 Posts
    just a side note:
    Code:
    undefined == null == 0 == '' == false
    the only return values you get from document.getElementById() are HTMLElement and null.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •