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
Ben Os
20,008 PointsJavascript - 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:
2 Answers
Matthew Garza
26,312 Pointsobject literal, a function and the "this" method, with dot natation this.name.toupperCase().
Matthew Garza
26,312 Pointshope this helps : )
Dave McFarland
Treehouse TeacherHow 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
- Inspect every element on a page for that text
- Extract the text in that element
- uppercase() Benia
- 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/
Ben Os
20,008 PointsBen Os
20,008 PointsI think toUpperCase() might be good but I need a way to target this particular element's-text.