JavaScript Replace characters in HTML elements replace characters html,replace html characters javascript,replace html characters

I'd recommend using the text function, for example:

var list = $('.category-list-replace');
list.text(function(i, text) {
    return text.replace(/\|/g, ",")
});

Note this also uses a regular expression (/\|/) with a global flag (g) to replace multiple occurrences of the | character.

$("#go").click(function() {
  var list = $('.category-list-replace');
  list.text(function(i, text) {
    return text.replace(/\|/g, ",")
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="category-list-replace">ksadj| lksd| sakdj</p> 
<p class="category-list-replace">sdawfe| nekesa</p> 
<p class="category-list-replace">opeiuf| elnfele</p>
<button id="go">Replace</go>
Answer:1

Is this something you're looking for?

list.each(function() {
  var $element = $(this);
  var text = $element.text();
  $element.text(text.replace('|', ','));
});
Answer:2

I have a Table with JQuery's selectable feature.My Table was selectable each td which are in the same column. Below is my full html <html> <head> <link href="/css/jquery-ui....

I have a Table with JQuery's selectable feature.My Table was selectable each td which are in the same column. Below is my full html <html> <head> <link href="/css/jquery-ui....

When using a for...of loop to iterate over an HTMLCollection returned from DOMParser only the odd elements are returned. I don't think this happens with NodeLists or HTMLCollections not created with ...

When using a for...of loop to iterate over an HTMLCollection returned from DOMParser only the odd elements are returned. I don't think this happens with NodeLists or HTMLCollections not created with ...

I use jquery.colorfy https://github.com/cheunghy/jquery.colorfy to change the key word color in the textarea. I can set value use $('#textarea').text("value"); to change my textarea value. The ...

I use jquery.colorfy https://github.com/cheunghy/jquery.colorfy to change the key word color in the textarea. I can set value use $('#textarea').text("value"); to change my textarea value. The ...

  1. keep textarea value after submit
  2. retain textarea value after refresh

Is it possible to differentiate between a group of buttons? Given the following buttons. <div id="slideout_inner"> <h2>Select Size</h2> <p id="group1"> <button type="...

Is it possible to differentiate between a group of buttons? Given the following buttons. <div id="slideout_inner"> <h2>Select Size</h2> <p id="group1"> <button type="...

  1. differentiate between group and team
  2. differentiate between group discussion and debate
  3. differentiate between group and period
  4. differentiate between group by and order by clause in sql
  5. differentiate between group velocity and phase velocity
  6. differentiate between group and individual counselling
  7. differentiate between group and ungrouped data
  8. differentiate between group work and case work
  9. differentiate between group and individual drive
  10. difference between group and team
  11. difference between group by and order by
  12. difference between group discussion and debate
  13. difference between group by and having
  14. difference between group and period
  15. difference between group by and partition by
  16. difference between group and team pdf
  17. difference between group velocity and phase velocity
  18. difference between group by and distinct
  19. difference between group by and order by in sql
  20. difference between group and set in tableau