Question

The structure of the dynatree is like this:

<ul class="dynatree-container">
 <li class="">
    <span class="dynatree-node dynatree-has-children dynatree-exp-c dynatree-ico-c">
        <a class="dynatree-title" href="#">Alimentary</a>
    </span>
</li>

<li class="">
  <span class="dynatree-node dynatree-expanded dynatree-has-children dynatree-exp-e dynatree-ico-e">
       <a class="dynatree-title" href="#">Fruits</a>
    </span>

    <ul style="">
      <li class="">
       <span class="dynatree-node dynatree-exp-c dynatree-ico-c">
         <a class="dynatree-title" href="#">Banans</a>
       </span>
     </li>
     </ul>
   </li>

   <li class="">
       <span class="dynatree-node dynatree-has-children dynatree-exp-c dynatree-ico-c">&gt; 
         <a class="dynatree-title" href="#">Cosmetics</a>
       </span>
  </li>
</ul>

I want to search through the data and if "pineapple" exists in the tree ,show it in bold. In javascript i wrote a method onkeyPressed:

 function Search(value)
    {

      for(var i=0;i<document.getElementsByTagName('li').length;i++)
       {
        var node=document.getElementsByTagName('dynatree-title')
        if (node.data.href ==value) {
            //expand the tree       
        }        
       }    
    }

I am not sure how can i visit all the nodes search for the value. Does anyone has an idea?

Was it helpful?

Solution

You can use Jquery to search the node:

function Search(value){
    $(".dynatree-title").each(function(){
        if($(this).text() == value){
            $(this).html("<strong>"+$(this).text() +"</strong>");
        }
    });
}

OTHER TIPS

If I understand correctly, you should check against innerHTML, not href:

if (node.innerHTML == value)

And then go on with your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top