Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing Character on Click Revisited 1

Status
Not open for further replies.

JBorges

Technical User
Jan 12, 2009
57
DK
thread216-1705590

@feherke
Some time ago you helped me removing a character from a text inside a div element. That works great, but now I need to have 2 characters removed with an ID value of 'mr' and 'fn' respectively. Please see the thread linked to with the working code of removing 1 character. Below is an extract of the code and what I tried but that does not extract both ID values:

else if (what.childNodes.nodeType == Node.ELEMENT_NODE && what.childNodes.id != 'mr' || 'fn')

else if (what.childNodes.nodeType == Node.ELEMENT_NODE && what.childNodes.id != 'mr' && 'fn')

I hope I'm clear enough here.

Thanks again for your help.

Philip
 
you need to repeat the comparison
Code:
else if (what.childNodes[i].nodeType == Node.ELEMENT_NODE && (what.childNodes[i].id != 'mr' || [COLOR=#CC0000]what.childNodes[i].id !=[/color] 'fn'))
 
Thanks jpadie.

The script still works but now it doesn't remove those ID's. My complete code is:

Code:
function getText(what)
{
    var result = ''
    
    for (var i = 0, l = what.childNodes.length; i < l; i++)
        if (what.childNodes[i].nodeType == Node.TEXT_NODE)
            result += what.childNodes[i].textContent
            else if (what.childNodes[i].nodeType == Node.ELEMENT_NODE && (what.childNodes[i].id != 'mr' || what.childNodes[i].id != 'fn'))
                result += getText(what.childNodes[i])
                
                return result.replace(/\s+/g, ' ')

}
 
@jpadie
Please scratch that last post. It works! Thanks a lot :)

I include some more code for others ... to make sense of it. The idea is that whenever you tap the number (in this case '18') the function gets the text but removes the '*' and the '+* signs. I'm using this code in my iOS app: it gets the text and displays it in a text view.

Code:
<b id="17:18" onClick="getText(document.getElementById('17_18'));>18 </b><vs id="17_18">Sample textSample textSample textSample textSample text,<a href='[URL unfurl="true"]http://pseudoLink1.html'[/URL] id='fn'>*</a> og den<a href='[URL unfurl="true"]http://pseudoLink2.html'[/URL] id='fn'>*</a> Sample textSample textSample textSample text,<a href='[URL unfurl="true"]http://pseudoLink3.html'[/URL] id='mr'>+</a> Sample textSample textSample text.<a href='[URL unfurl="true"]http://pseudoLink4.html'[/URL] id='mr'>+</a> </vs>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top