Reputation: 460
I have to convert table to csv I am using following logic to concatenate strings of each td
var $text=(table.rows[0].cells[i].innerHTML.split(", ").join("")).toString();
Assume $ text actually holds the <font class="Major">testcasedff</font>;
When I tried to use Find function for extracting data
var data=$text.find('font').text();
It actually doesnt work .I am using IE9 as test browser and im getting the following script error
Line: 300 Error: Object doesn't support property or method 'find'
Please refer to the Fiddle below
Upvotes: 1
Views: 370
Reputation: 42054
Try:
In the following row JQuery convert an HTML Element from string to JQuery Object and so your op will be simplified:
var fontObj = $("<font class='Major'>this is a test</font>");
var $textfontObj.text();
In pure javascript You will need to create a dummy element, insert yout HTML Element from string and then get the desired result:
var targetEleContainer = document.createElement('div');
targetEleContainer.innerHTML = "<font class='Major'>this is a test</font>";
var out2=(targetEleContainer.firstChild).innerHTML;
bye
Upvotes: 1
Reputation: 460
textContent dom Property and Parse html works
var $text="<font class='Major'>this is a test</font>";
var result='';
var data=$.parseHTML($text);
$.each(data, function (i, el) {
result += el.textContent;
});
alert(result);
Please Checkout the Fiddle
http://jsfiddle.net/Abinaya_WEBGurl/8zrhgy6v/3/
Upvotes: 0