замена текста html тегами
возникла труднось обернуть искомый текст в html теги
вот такой вот поиск у меня $('.article p, .article h2').each(function() { var text = $(this).text().replace(/nor/ig, "$&"); $(this).text(text); }) мне нужно както обернуть $& тегами <span style="color.red"></span>, чтоб найденный текст выделялся... за ранее благодарен |
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(function() { $('.article p, .article h2').each(function() { console.log($(this).text().match(/nor/ig)) var text = $(this).text().replace(/nor/ig, '<span style="color:red">$&</span>'); $(this).html(text); }) }); </script> </head> <body> <div class="article"> <h2>qwernorqwerty</h2> <p>qwernOrqwerty</p> </div> </body> </html> |
Часовой пояс GMT +3, время: 09:06. |