Ask coding questions

← Back to all posts
sense text in a website (not fully answered yet)
Chewyblockguy (9)

I need the code for js to sense text in a website and replace it with an image. @ch1ck3n answered partly (

var searchTerm = 'This is',
    replaceWith = 'This is new',
    updateObj = {};
$("#sheet div.item:contains('" + searchTerm + "')").each(function(){
   // use id to build an update object
    updateObj[this.id.replace('field-', '')] = {
        oldText: searchTerm, 
        newText: replaceWith
    }; // not sure what you are trying to save here
   // manipulate html
   this.innerHTML = this.innerHTML.replace(searchTerm, replaceWith);
});
// after, send ajax data `updateObj

)
which was very helpful but it doesnt work in a way that lets me replace the text with an image. pleasehelp me with this. I need it to make a certain addon to the scratchaddons extension. thanks!

Answered by ch1ck3n (1632) [earned 5 cycles]
View Answer
Comments
hotnewtop
ch1ck3n (1632)

What do you mean by "sense text"?

Chewyblockguy (9)

@ch1ck3n for instance if I needed to find out if a website had the word hello than what code would I use to find out if and where that text is

ch1ck3n (1632)

@Chewyblockguy

var searchTerm = 'This is',
    replaceWith = 'This is new',
    updateObj = {};
$("#sheet div.item:contains('" + searchTerm + "')").each(function(){
   // use id to build an update object
    updateObj[this.id.replace('field-', '')] = {
        oldText: searchTerm, 
        newText: replaceWith
    }; // not sure what you are trying to save here
   // manipulate html
   this.innerHTML = this.innerHTML.replace(searchTerm, replaceWith);
});
// after, send ajax data `updateObj`
Chewyblockguy (9)

@ch1ck3n wow thx! could you possibly make it so I can make it an image instead of new text

Chewyblockguy (9)

@ch1ck3n dang it. oh well Ill see what I can do. thx again!