Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post

    How to compare '&' in XML and HTML using JS

    Hello,

    I have a script that compares XML attributes to HTML content. The problem I am having is when I need to use '&'. Do I need to do something with CDATA or can i look for '&' in the JS and replace it?

    The XML
    Code:
    <item term="EB &#038; AO" def="EB has a definition" rollover="EB has a rollover" />
    The HTML
    Code:
    <a class="glossaryLink" href="#" onmouseover="onRollOverPULink(this,event);" onmouseout="onRollOutPULink();" onclick="showHideGlossary(this)">EB &amp; AO</a>
    The JS
    Code:
    function onRollOverPULink(elem,evt)
    {
    	var mouseX = evt.clientX;
    	var mouseY = evt.pageY;
    	var targetSpan = $("#glossaryContent").find($('#' + elem.innerHTML.toLowerCase().replace(/\W/g, '')));
    	
    	$("#glossaryToolTip").html(targetSpan.attr('rollover'));
    	$('#glossaryToolTip').css({display:'block', position: "absolute",'top':(mouseY - 45),'left':(mouseX - 18)});
    }

  • #2
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    Use the function replace with something like this :
    Code:
    // for elem.innerHTML
    var trmWith="EB &amp; AO";
    alert(trmWith.replace(/&amp;/g,'&'));
    // for XML
    var trmWithout="EB & AO";
    alert(trmWithout.replace(/&/g,'&amp;'))
    Last edited by 007julien; 11-18-2013 at 09:18 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •