I have some code here that looks for every mention of “[code]” and turns it into <code> but I only want to do this within a specific jquery element…
function formattxt(text){
if (text == '') return '';
var start = text.indexOf('[code]');
var end = text.indexOf('[/code]', start);
...
How would I do that?
I’m looking for something simple like the following:
var start = $("#element").text.indexOf('[code]');
var end = $("#element").text.indexOf('[/code]', start);
To Enable the replacement, you’d better use
replace:If you want ot use
indexOf, use the following as mentioned by @zzzzBovBe careful with
indexOf, as it is not supported by IE6-8, You need to include thid code to function in all browsers.