Aamir Shahzad
Aamir Shahzad

Reputation: 6834

JQuery selector for text in a div

I want to select 8:30 space with space that comes from server, I want to select and trim that space and insert it back.

I have tried selecting it like $('.time-wrapper').text() it give me all text also .prev() and .next() with $('.time-wrapper span').prev(); and $('.time-wrapper br').next() but its not helping also challenge will be insert it back there.

<span class="time-wrapper">8:30 <span>&nbsp;am</span>&nbsp;PT  </span>

Any help is appreciated. If I am not clear do ask in comments.

Upvotes: 0

Views: 42

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82251

You can use:

var textnode= $('.time-wrapper').contents().first()[0]; //get javascript object of text node
textnode.textContent = textnode.textContent.trim(); //trim and replace text

Working Demo

Upvotes: 1

Related Questions