Skip to main content
Trademark capitalization; acronym capitalization; layout; Added [jQuery].
Source Link
Tushar
  • 3k
  • 1
  • 21
  • 28

Jquery jQuery replace htmlHTML

In a portion of my code to get a "report view" where the element is different (textarea becomes a div or span) and use the same data with newlines I replace the new lines with page breaks.

Currently the function I use:

$.each($('[id^="mytext-text"]'),(i,e)=>{$(e).html($(e).html().replace(/\n/gm,'<br>'))})

I often find myself using this same format for replacing other things, i.e.,

$(e).text($(e).text+'more text');

Is there a better way (either about using line breaks or about the .text(.text())? I've seen suggestions to simply write your own function butbut I feel like that doesn't solve the generalized problem.

Jquery replace html

In a portion of my code to get a "report view" where the element is different (textarea becomes a div or span) and use the same data with newlines I replace the new lines with page breaks.

Currently the function I use:

$.each($('[id^="mytext-text"]'),(i,e)=>{$(e).html($(e).html().replace(/\n/gm,'<br>'))})

I often find myself using this same format for replacing other things, i.e.,

$(e).text($(e).text+'more text');

Is there a better way (either about using line breaks or about the .text(.text())? I've seen suggestions to simply write your own function but I feel like that doesn't solve the generalized problem.

jQuery replace HTML

In a portion of my code to get a "report view" where the element is different (textarea becomes a div or span) and use the same data with newlines I replace the new lines with page breaks.

Currently the function I use:

$.each($('[id^="mytext-text"]'),(i,e)=>{$(e).html($(e).html().replace(/\n/gm,'<br>'))})

I often find myself using this same format for replacing other things, i.e.,

$(e).text($(e).text+'more text');

Is there a better way (either about using line breaks or about the .text(.text())? I've seen suggestions to simply write your own function but I feel like that doesn't solve the generalized problem.

Source Link

Jquery replace html

In a portion of my code to get a "report view" where the element is different (textarea becomes a div or span) and use the same data with newlines I replace the new lines with page breaks.

Currently the function I use:

$.each($('[id^="mytext-text"]'),(i,e)=>{$(e).html($(e).html().replace(/\n/gm,'<br>'))})

I often find myself using this same format for replacing other things, i.e.,

$(e).text($(e).text+'more text');

Is there a better way (either about using line breaks or about the .text(.text())? I've seen suggestions to simply write your own function but I feel like that doesn't solve the generalized problem.