0

I was wondering if jQuery (or maybe a plugin of jQuery) has the ability to select a text in the page so I could replace it. Similar to what is done in AngularJS with {{myExpression}} - what I would like to do is select {{myExpression}} and replace it with something else using jQuery.

Yes - I know I can have an empty span with an id and change it's inner text - that's not what I need.

Thank you

developer82
  • 12,550
  • 20
  • 80
  • 143

2 Answers2

1

Use a variation of the :contains selector.

http://api.jquery.com/contains-selector/

Example given:

<div>John Resig</div>
<div>George Martin</div>
<div>Malcom John Sinclair</div>
<div>J. Ohn</div>

<script>
$( "div:contains('John')" ).css( "text-decoration", "underline" );
</script>

Edit: Upon further research, this appears to be a duplicate of these questions:

Community
  • 1
  • 1
digitalextremist
  • 5,932
  • 3
  • 41
  • 61
1

$('*:contains("myMessage")') returns a jQuery object that contains matched elements

pgerstoft
  • 489
  • 6
  • 15