SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    790
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I Use jQuery To Style Every Instance Of A Word?

    I am wanting to add a style (bold and blue for example) to every instance of a word or words on my website. Is this possible with jQuery? And how would I write it?

    For Example:

    Use a jQuery command to style the words "Company" into "Company" (bold and blue).
    Todd Temple > T2 Design

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm afraid it would not be straightforward.

    To style text it would first need to be enclosed with a <span> tag.

    There is no selector to do what you want so you are in to traversing the DOM to locate occurrences and then manipulating the html within it.

    The .text method returns the text within an element that includes any elements it contains. So for example $("body").text() should return the whole text of the document.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •