drupal 7 - use jquery to find any character and remove it -
i have website in drupal. there seems problem it. before end of body tag digit appears 9. need remove through jquery.
i know there find() method in jquery finds element not character. need find character , remove it. doesn't comes under element body tag cannot select element surrounds , remove it.
<body>all other site elements....9</body>
i need remove 9. please suggest. thanks
you should find reason character appended, , remove that. however, client-side temporary fix:
you don't want manipulate innerhtml
(or .html()
) of entire document. instead, grab last child node of document.body
(so far, jquery can that), verify it's text node (jquery falls short @ point), , shorten text content little. neither textcontent
, innertext
cross-browser compatible (though might hope innertext
become standard). however, text nodes, nodevalue
available:
$(document).ready(function(){ var node = document.body.lastchild; if(node && node.nodetype == node.text_node){ node.nodevalue = node.nodevalue.replace(/9^/,"") } })
note 9 assumed last thing appears in body, , there no invisible content following (whitespace, script tags, comment tags). whitespace can ignored modifying regex (left excercise reader), , skipping invisible nodes can de done via iteration (easier if tailored particular situation; it's temporary fix after all).
useful links:
https://developer.mozilla.org/en-us/docs/dom/node.lastchild
https://developer.mozilla.org/en-us/docs/dom/node.nodetype
https://developer.mozilla.org/en-us/docs/dom/node.nodevalue
https://developer.mozilla.org/en-us/docs/dom/node.previoussibling
Comments
Post a Comment