1

Just when I thought I was done, I found in between my selected pagination '5' for example below, double hard coded non-breaking spaces  . I don't have access in the cms to override this, so jquery is required.

What is the solution to be sure the pagination gets selected, not the  . Please check out the fiddle so you can demo the exact experience.

fiddle http://jsfiddle.net/evanmoore/9AMnU/2/

HTML

<a href="http://www.example.com">4</a>
&nbsp;5&nbsp;
<a href="http://www.example.com">6</a>

This jquery cleans up and span tags around the pagination

$('.pag').each(function () {
  $(this).contents().filter(function () {
    return this.nodeType === 3 && $.trim(this.textContent) !== '' 
  }).first().wrap('<div/>').parent().html(function (i, v) {
        return v.replace(/(\w)/, '<span>$1</span>')
      }).replaceWith(function () {
        return this.innerHTML;
      })
})
Evan
  • 3,411
  • 7
  • 36
  • 53

2 Answers2

1

try this code

$('.pag').each(function () {
  $(this).contents().filter(function () {
    return this.nodeType === 3 && $.trim(this.textContent) !== '' 
  }).first().wrap('<div/>').parent().html(function (i, v) {

        v= v.replace("&nbsp;","");

        return v.replace(/(\w)/, '<span>$1</span>')
      }).replaceWith(function () {
        return this.innerHTML;
      })
})

i changed

v= v.replace("&nbsp;","");

UPDATE

try this

v= v.replace(/&nbsp;/g,""); 

to remove multiple occurrences instead of rewriting the above code twice .

Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193
  • when i doubled it up, like this, then it got rid of all the non breaking spaces http://jsfiddle.net/9AMnU/3/ – Evan Jan 11 '13 at 12:34
0

you can use

$.trim()

to remove spaces both at starting and ending

Hary
  • 5,690
  • 7
  • 42
  • 79