I have created an XML file and can successfully parse the file in jQuery. The XML file consists of pairs of selectors and css/html manipulators.
For example: Here is the console.log.
found session
found child selector
attributes$(“.monday td.session.m_2_title”)
attributes.css(“background-color”, “#00ffff”);
$(“.monday td.session.m_2_title”).css(“background-color”, “#00ffff”);
Here is the example code:
$(xml_Data).find("session").each(function() {
console.log("found session");
$(this).children().each(function(){
var tag = this.tagName;
console.log("found child " + this.tagName);
console.log("attributes" + $(this).text());
if (this.tagName == "selector"){
//$(this).next();
console.log("attributes" + $(this).next().text());
console.log($(this).text() + $(this).next().text());
$(this).text() + $(this).next().text();
}
});
});
In a fit of wild optimism I thought this:
$(this).text() + $(this).next().text();
Would cause the script to run the concatenated strings a statement. Obviously this is wrong.
The the question is how do I put the xml data together to create and run the appropriate statement.
You need to create a tag with jQuery, put output of this line (
$(this).text() + $(this).next().text()) into it and insert it into your document.Or you may use eval(“code in string here”), which is not recommended.
Or you may use function declaration like this:
var foo = new Function ([arg1[, arg2[, ... argN]],] functionBody)where function body should be a string with your JS code