Replace every tab (key) with string in jQuery?
I need to go though a content of element, and replace every tabulator \t w开发者_开发技巧ith text "(Here's a tab)". How is this possible?
Martti Laine
You can use the replace()
method on a string:
var el = $('#myEl').text();
el.replace(/\t/g, "(Here's a tab)");
Note: you must use a regular expression with the /g
modifier to replace every instance of \t
, using a string for the search will only replace the first occurrence.
精彩评论