1

I have variable holding a html table. there are double quotation marks in this html table.I want to remove html tag from this table. so I applied normal string manipulation method on this variable.but it didn't work.can you help me convert it to a normal string.

here is the try I have done.here the directionDataHolder is holding the html table.

 var tmp = document.createElement("DIV");
 tmp.innerHTML = directionDataHolder;
 var data = tmp.textContent||tmp.innerText;
5
  • What did you try? Post the code. Commented Jul 25, 2011 at 4:21
  • I took that code from stackoverflow Commented Jul 25, 2011 at 4:33
  • It's not exactly clear what you're trying to do. Do you just want get the text of the HTML table without the HTML tags? Commented Jul 25, 2011 at 4:36
  • yeap that's I want but I can't do it, because as I think there is double quotation in that directioanDataHolder variable. Commented Jul 25, 2011 at 4:41
  • problem was solved.in order to work above code it should wrap by html and body tags.thanks all for help........:) Commented Jul 25, 2011 at 5:11

2 Answers 2

2

If you need to get just the text from an HTML table stored in a string, then probably the easiest way is to use jQuery or some other framework:

var tbl = '<table border="1"><tr><td>Cell 1</td><td>Cell 2</td></tr></table>';
var text = $(tbl).text(); // text is "Cell 1Cell 2".

If you want to get the text of a single cell, you can do this:

var text = $(tbl).find('td').eq(0).text(); // text is "Cell 1"

More information on jQuery

Sign up to request clarification or add additional context in comments.

Comments

0

Now, I'm not so sure this is what you were asking after you edited your question. But, these are the steps to turn HTML text into a javascript string:

  1. Put a backslash in front of all single quote marks like this: It\'s going to be hot.
  2. Remove all newlines so the HTML is all on one line.
  3. Surround the remaining text with single quotes: It\'s going to be hot
  4. Assign it to a javascript variable like this:

    var str = 'It\'s going to be hot';

Or, you can try this online converter. Paste your HTML in, pick the type of output you want and press the Convert button.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.