Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Javascript - Know a way to target a particular word in all pages of a site?

I have a word "Benia" that repeats itself in different pages of my site.

I need a way using JS to captilize all letters of this word.

Where ever it is written: "Benia" I want it to be "BENIA".

Do you know a way? Thanks.

Tagging our beloved teacher:

Dave McFarland

I think toUpperCase() might be good but I need a way to target this particular element's-text.

2 Answers

object literal, a function and the "this" method, with dot natation this.name.toupperCase().

hope this helps : )

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Ben Aharoni

How many pages are on your site? If there aren't a lot of pages, you should just manually change the text to uppercase. Creating a script to do this seems like overkill -- a fair amount of programming and could potentially impact performance of your site, since you'd need to

  1. Inspect every element on a page for that text
  2. Extract the text in that element
  3. uppercase() Benia
  4. Add text back into the element

If you want to try it though, a good place to start is the jQuery :contains() selector: http://api.jquery.com/contains-selector/