views:

1414

answers:

3

I used the function:

document.getElementsByTagName('strong')

to get all the text in a page with that type of formatting. The HTML looks like:

<td align="center" valign="bottom"><H1><font size="+4"><strong>TEXT_HERE</strong></font> <br>

I would like to change "TEXT_HERE" to maybe something else or remove it all together. How might I go about doing that?

Thanks in advance for your help :)

+5  A: 

With a for loop?

var strongElems = document.getElementsByTagName('strong');
var wantToHide  = true || false;

for (var i=0; i<strongElems.length; i++)
{
  var thisElem = strongElems[i];
  if (wantToHide)
  {
    thisElem.style.display = "none"; // hide it
  }
  else
  {
    thisElem.textContent = "something else"; // change it
  }
}
Tomalak
the textContent did it :) where do you find all the functions you can use to do snazzy stuff? thanks :)
Casey
Google. :-D (SCNR). As far as documentation goes: For Firefox, the Mozilla Developer Center is the way to go, for IE basically everything is in the MSDN. The rest is in Google.
Tomalak
A: 

When I wanted to change some text in a web page, I based my Greasemonkey solution on DumbQuotes. I liked that I could easily define replacement pairs into a list:

replacements = {
  "old": "new",
  "foo": "bar",
};

That said, I'll check out Tomalak's solution as well. Thanks for posting this question.

Philip Durbin
A: 
// ==UserScript==
// @name           MyScript
// @namespace      http://example.com
// @description    Example
// @include        *
//
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js
// ==/UserScript==

var shouldHide = false;

$.each($('strong'), function() {
  if(shouldHide) {
    this.hide();
  } else {
    this.text = "New Text";
  }
});
Daniel X Moore