mercredi 26 avril 2017

Show / Hide DIV with Javascript from external variable

I would like to hide or show a DIVs depending on variable coming from a XML file.

    <div id="LINK_FAV_1">
    <a href="#" class="list-group-item active">Link 1</a>
    </div>

    <div id="LINK_FAV_2">
    <a href="#" class="list-group-item active">Link 2</a>
    </div>

I tried that script, but it does not work can you tell me what is wrong please ?

<script>
for(i = 1; i <= 2 ; i++)    
document.getElementById('LINK_FAV_'+i).style.display = getXMLValue(xmlData, 'DIV_LINK_FAV_'+i);
</script>

XML file is as follow :

<response>
<DIV_LINK_FAV_1>'none';</DIV_LINK_FAV_1>
<DIV_LINK_FAV_2>'block';</DIV_LINK_FAV_2>
</response>

If necessary, i can change at client side the XML variable answer if current syntax such as : 'none'; or 'block'; is not appropriate.

Many thanks for your help,




Aucun commentaire:

Enregistrer un commentaire