0

I am removing extra space using trim method which is working fine in all browser except IE8.

<head>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
$('a').click(function(){
console.log($('div').text().trim())
})})
</script>
</head>
<body>
<div>   test </div>
<a href="javascript:void(0)">pick test</a>
</body>
Jitender
  • 7,057
  • 25
  • 92
  • 193

3 Answers3

3

Use jQuery's trim:

$.trim($('div').text())

text() returns a string so you are trying to use the browser's built in trim which IE8 does not have.

James Montagne
  • 75,784
  • 13
  • 108
  • 129
1

try below

$.trim($('div').text())
Santosh
  • 11,930
  • 4
  • 40
  • 72
0

Use $.trim() jquery method instead:

console.log($.trim($('div').text()))
A. Wolff
  • 73,242
  • 9
  • 90
  • 149