Help with Javascript innerHtml please

greddin used Ask the Experts™
I have a Javascript that is looping through a table's rows.  One of table cells (TD) contains a date.   Here's a sample:

<td class="ms-cellstyle ms-vb2"><span class="ms-noWrap" title="10/30/2015">10/30/2015</span></td>

Open in new window

I have a variable named "col_date" which needs contain just the date (10/30/2015).

var col_date = row.cells[suspense_date_column].innerHTML;

Open in new window

Right now col_date contains the whole  
<span class="ms-noWrap" title="10/30/2015">10/30/2015</span>

Open in new window

.  How can I return just the date without the span tag?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015
Maybe this:
var col_date = row.cells[suspense_date_column].getElementsByTagName('span')[0].innerHTML;

Open in new window

Senior Software Developer
use the innerText or textContent property rather than innerHTML.

Not all browsers support both innerText and textContent but all browsers should support at least one or the other.
Most Valuable Expert 2013
Awarded 2012

+1 for Tom`s solution

Question: the HTML of the cell looks like a SharePoint generated table (at least the class names do :-))

Why dont you use jQuery?

Alternative solution:
var col_date = row.cells[suspense_date_column].getElementsByTagName('span')[0].getAttribute("title"); 

Open in new window



Thanks, both solutions are perfect. Appreciate the help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial