Check If Text In Cell Is Bold
I have a table in html. Some cells is bold and some is normal. How I can check if some cell is bold (for example i,j) and get text of that cell without tag . Cells can have only te
Solution 1:
See this answer how to get a reference to the cell: https://stackoverflow.com/a/3052862/34088
You can get the first child with cell.firstChild
. This gives you a text node or a <B>
node. You can check this with the node.nodeType
which is 1 for DOM nodes or 3 for text nodes. Which gives:
functionisBold(table, rowIdx, columnIdx) {
var row = table.rows[rowIdx];
var cell = row.cells[columnIdx];
var node = cell.firstChild;
if( node.nodeType === 3 ) {
returnfalse;
}
return node.nodeName === 'b' || node.nodeName === 'B';
}
Solution 2:
Use the css font-weight property to detect if the text is in bold:
if ($("#td-id").css("font-weight") == "bold") {
var boldText = $("#td-id").html();
// Text is bold
}
If you don't use css, there must be a <strong>
-tag (or <b>
-tag) inside the table cell contents. You may extract the bold text with the following code:
var boldText = $("#td-id strong").html();
if (boldText != NULL) {
// Text is bold
}
Post a Comment for "Check If Text In Cell Is Bold"