Link to home
Start Free TrialLog in
Avatar of Jesper Christensen
Jesper Christensen

asked on

jquery selector question

Hi.
I need to select the text "test", but cant figure it out :)


<div id="Price1">
<span id="SpecialOffer">122</span>
test
</div>

I´ve tried with :not, but dosent work.
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Test page : http://jsfiddle.net/8x41z56e/
var text = $("#Price1").contents().filter(function() { return this.nodeType == 3; }).text();
// remove carriage return
text = text.replace(/^[\r\n]+|\.|[\r\n]+$/g,"");

Open in new window

Avatar of Jesper Christensen
Jesper Christensen

ASKER

Well, If I want to hide the text or change the style, i cant use it as a var.?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Bongii,

Try with following code:
function selectText(containerid) {
        var div = document.getElementById(containerid);
        var oldstring = div.innerHTML; // Stores Current text inside Div Tag
        $(div).find('span').remove(); // Removes Span tag
        alert(div.innerHTML); // display your required text 'test'
        div.innerHTML = oldstring; // Restoring old value to div
    }

Open in new window