You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

Troubleshooting a (probably stupid) javascript error

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

0
b/Web publicado por u/WholeWheatBagels November 12, 2016, 01:17:31 AM
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.
Last Edit: November 12, 2016, 01:30:49 AM by WholeWheatBagels
Inicia sesión o crea una cuenta para dejar un comentario
u/Snektron November 12, 2016, 09:39:21 AM
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.
u/ben_g November 12, 2016, 12:03:27 PM
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');}
u/WholeWheatBagels November 13, 2016, 01:05:21 AM
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?

u/p2 November 15, 2016, 11:55:03 AM
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... ^^
Last Edit: November 15, 2016, 12:05:32 PM by p2
Start a Discussion

b/Web

Website developement and scripting

68
Topics
Explore Board
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal