Join us on Discord!
You can help CodeWalrus stay online by donating here.

Troubleshooting a (probably stupid) javascript error

Started by WholeWheatBagels, November 12, 2016, 01:17:31 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

WholeWheatBagels

So I've been messing around with Javascript lately.
I wrote this to mess with some page code:

javascript:
var divs = document.getElementsByClassName("corrupted-repair-button");
for (var x = 0; x < divs.length; x++) {
    var elem=divs[x];
    elem.removeAttribute('hidden')
}

What I'm trying to do is remove a "hidden" attribute from an element with that class name.
Thing is, it works in the Inspect console,but when I stick it in a bookmark or the onmibar it never works and I have no idea why.

Pretty new to JS so it's probably staring me straight in the face and I haven't caught it yet.
Living in another world to you.



Also in case you were wondering Frankie did go to Hollywood

Snektron

But does it work when you paste it in the addres bar? Watcvh out though, Chrome removes the javascript: part when you paste it sop you have to type it manually. Im not sure it it does that with bookmarks too.
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


ben_g

I don't think bookmarks are supposed to contain multiple lines. Have you tried writing it all on one line like this?

javascript:var divs=document.getElementsByClassName("corrupted-repair-button");for (var x=0;x<divs.length;x++) {divs[x].removeAttribute('hidden');}

WholeWheatBagels

I have tried all of the above to no luck. Bookmarks automatically put everything on the same line, so no problems there; I know they work b/c the image replacer script (BATMAN) works as a bookmark.

Maybe it has something to do with the console needing to be in this mode and not the default "top" mode?

Living in another world to you.



Also in case you were wondering Frankie did go to Hollywood

p2

in your first post... I think you forgot the ; after the elem.removeAttribute('hidden')
*Will try something out, now ^^

ok this code worked for me:

var divs = document.getElementsByClassName("corrupted-repair-button");
for (var x = 0; x < divs.length; x++) {
  divs[x].style.hidden='';
}



If you have jQuery you can do it a lot eaier by just calling
$('.corrupted-repair-button').style.hidden='';
At least I think so... ^^
  • Calculators owned: ti-83+, ti-84+, ti-84+, ti-84+se, ti-84+se(te), ti-nsphire, ti-nsphire CAS, ti-nsphire CX-CAS, ti-voyage, ti-voyage, Who reads this list anyways...?
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

Powered by EzPortal