I want to separate some words with JSON and print underlined words with JSON
Example JSON Data: {'term':'word1','term':'word2','term':'word3',..}
What have I done?
function wrapSentence(sentence) {
$.getJSON( "ajax/test.json", function( data ) {
var items = [];
$.each( data, function( key, terms ) {
// Get element contents and split by whitespace git
var words = $sentence.text().split(/\s+/);
// Create an empty array for storing wrapped elements
var wrapped = [];
// Loop through each word and wrap
for (var i = 0; i < words.length; i++) {
if(words[i] != terms) {
wrapped.push('<span>' + words[i] + '</span>');
} else {
wrapped.push('<span style="text-decoration: underline;text-decoration-style:dashed;">' + words[i] + '</span>');
}
}
// Combine words into a string
return wrapped.join(' ');
});
});
}
I can get data with getJSON, but I can't print. What could be the reason for this?