Skip to content
Advertisement

Javascript .replace command replace page text?

Can the JavaScript command .replace replace text in any webpage? I want to create a Chrome extension that replaces specific words in any webpage to say something else (example cake instead of pie). Answer The .replace method is a string operation, so it’s not immediately simple to run the operation on HTML documents, which are composed of DOM Node objects.

Replace too long strings with “…”

Lets say we have a <div style=”width:100px;”>This text is too long to fit</div> The text in the div is dynamic. And I’d like to force the text to fit in width and not break. So i need some kind of functionality to test if the text is going to fit, and if it is not, then i’d like to display

Wait until a condition is true?

I’m using navigator.geolocation.watchPosition in JavaScript, and I want a way to deal with the possibility that the user might submit a form relying on location before watchPosition has found its location. Ideally the user would see a ‘Waiting for location’ message periodically until the location was obtained, then the form would submit. However, I’m not sure how to implement this

Cannot read property length of undefined

I am trying to simply check if I have an empty input text box but I get this error when I run this in Chrome: Uncaught TypeError: Cannot read property ‘length’ of undefined. Here is how I go about doing it. I check for DOM readiness and then call the function: Answer The id of the input seems is not

Javascript Regular Expression Remove Spaces

So i’m writing a tiny little plugin for JQuery to remove spaces from a string. see here my regular expression is currently [ ]+ to collect all spaces. This works.. however It doesn’t leave a good taste in my mouth.. I also tried [s]+ and [W]+ but neither worked.. There has to be a better (more concise) way of searching

from green to red color depend on percentage

I have a poll system and I want answers for this poll to be colored. For example: If it’s 10% it would be red, if 40% it would be yellow and if 80% it would be green, so I want my javascript code to use the rgb colors to make a color according to the given percentage. Now I want

missing ) in parenthetical

I keep getting that my javascript is missing ) in parenthetical [Break On This Error] if ( (this.scrollTop &lt; this.scrollH…uches[0].pageY > scrollStartPosY+5) ) And I cannot for the life of me figure out why. Answer Try JS Lint. It’s great for finding non-obvious syntax errors on scripts.

Advertisement