0

I have working Jquery written in this format to rename a span:

// [A]
let _href_w = $('span').filter(function () {
    return this.innerHTML == 'originalText';
})
_href_w.text("replaceOriginalText") //rename span

now I need a function to replace the placeholder of textarea:

HTML
<textarea placeholder="TypeHere"></textarea>

JQUERY
var textarea = $('textarea').filter('[placeholder="TypeHere"]');
textarea.attr('placeholder','replaceTypeHere');

but I would like it to be written like [A]

I tried:

let _href_w = $('textarea').filter(function () {
    return this.attr('placeholder') == 'TypeHere';
})
_href_w.attr('placeholder','replaceTypeHere') //rename textarea_placeholder

but error shows: this.attr is not a function

how can I rewrite this?

Level1Coder
  • 471
  • 6
  • 18
  • 1
    Your `this` is an element. Either wrap it in jQuery in order to use jQuery's `.attr`, or (better, IMO) consider using vanilla DOM methods instead, there are very few things you can do with jQuery that can't be done just as easily without a library – CertainPerformance Dec 27 '22 at 00:48

0 Answers0