Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3959696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:45:43+00:00 2026-05-20T02:45:43+00:00

I have a class for DIVs called .post and I’d like to find words

  • 0

I have a class for DIVs called .post and I’d like to find words inside that element and replace them with something else. That words must also not be inside elements with other classes (.tiptrig and .postheader).

I’d really like to achieve this but I don’t know how… I am new to Javascript and especially jQuery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:45:44+00:00Added an answer on May 20, 2026 at 2:45 am

    Seems like an easy task.

    $('.post').each(function() {
        $(this).html(function(index, html) {
            return html.replace(/THEWORD/g, 'something else');
        });
    });
    

    This would iterate over all nodes which own the class .post and replace the word THEWORD with something else. Be aware of that his is dangerous too because you could also modify HTML tag names for instance. So this only makes sense if you want to add/modify HTML code aswell.

    demo: http://www.jsfiddle.net/XGuGy/

    Probably a better idea to access the text():

    $('.post').each(function() {
        var $this = $(this);
    
        if( !$this.closest('.postheader').length && !$this.closest('.tiptrig ').length ) {
             $this.text(function(index, text) {
                return text.replace(/you/g, 'you fool');
             });
        }
    });
    

    demo: http://www.jsfiddle.net/XGuGy/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a whole bunch of divs that have a class called ofint .
I've got a div called 'menu' and inside that menu there are some divs
I have a list of divs that may or may not have a class
I have a couple of Divs which I style using a class and an
I have class method that returns a list of employees that I can iterate
I have class with a member function that takes a default argument. struct Class
In a page with n divs of the same class, I want to have
I have one class of divs ('open') the contain another class of divs ('items')
I have html that has 2 divs with the same id's in jquery i
I have 2 divs that I am creating from an array: $.each(data, function(i,item) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.