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
  • 13,237
  • 21
  • 88
  • 153
  • 3
    Yes, jQuery, in fact _JavaScript_ can do it. – Ram Jan 21 '14 at 18:02
  • Why don't you use AngularJS then? – Coder Jan 21 '14 at 18:02
  • @ShijuKBabu can't use AngularJS (although I really wanted to) since this project I'm working on should support older browsers (I'm talking as old as IE6 - YES!!! I know!!!!) and Angular is not supported under 8 I think. – developer82 Jan 21 '14 at 18:07

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,952
  • 3
  • 43
  • 62
1

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

pgerstoft
  • 489
  • 6
  • 15