I have done some stuff in jQuery and Javascript before, but unfortunately I am no expert. I couldn't find any hints on how to accomplish my task with using as few resources as possible. You guys can probably help me out:
Here is what I want to do:
I want to find (using regex) all BB-code-like elements on a page that look something like this:
[ndex here=parameter randomdata]
I want to then replace each of them with the contents I receive from an ajax-call that looks like this:
call.php?ndex=here=parameter randomdata
or whatever parameters I pick up from within the according [ndex]-tag.
Here is my solution/thought-process so far:
$(document).ready(function() {
var pattern = /\[ndex\s+(.*?)\]/mg;
var documentText = $(document.body).text();
var matches = documentText.match(pattern);
$('*').each(function () {
var searchText = this;
if ($(searchText).children().length == 0) {
$.each(matches, function() {
//here is where I would need to check for a match and make a call
}
});
}
});
});
I don't really know how to work from here. My sketch seems really clunky and complicated. There must be a more elegant and straight-forward solution.
Thank you guys so much for your help. :)