Skip to content
Advertisement

Is there a way to hide chars on start point?

The “$$$” chars were used for get indexof and hide list in code behind. Now I want to ask is there a way to hide these chars with jQuery and/or JavaScript?

$$$<ul id = "myid"class = "listbranch">
       <li>Битола</li>
       <li>Скопје</li>
       <li>Охрид</li>
       <li>Прилеп</li>
       <li>Ресен</li>
       <li>Гостивар</li>
       <li>Куманово</li>
       <li>Гевгелија</li>
       <li>Штип</li>
       <li>Велес</li>
       <li>Пробиштип</li>
       <li>Тетово</li>
       <li>Кочани</li>
       <li>Валандово</li>
       <li>Струмица</li>
       <li>Крива Паланка</li>
       <li>Кавадарци</li>
       <li>Неготино</li>
       </ul>$$$

 

Advertisement

Answer

You could put them in an element like <span class="hide">$$$</span> and then use JQuery to hide the element using the following,

//hide the element with the hide class
$(".hide").hide();

Another soution is to wrap the $$$ in a span tag and hide them using css as suggested by user5295483 comment. However I would suggest using a class name just in case you don’t want to hide all of your span tags.

HTML:

<span>$$$</span>

CSS:

 span{
       display:"none";
 }

  /* use this class if you don't want to hide all span tags*/
 .hide{

     display:"none";

 }

If you want hide the $$$ using plain JavaScript? You can try the following:

Live Demo

    //Call the hide function,
    //the $ must be escaped so that regexp will pick up all three of them
    hide(/$$$/);

    function hide(text) {//begin function

     //create a new RegExp object with the global replacement flag
     var search = new RegExp(text,"g");        


    //wrap the $$$ with a span element
    document.body.innerHTML = document.body.innerHTML.replace(search, "<span class='hide'>$$$$$$</span>");


    //store the collection of elements with the hide class
    var collection = document.getElementsByClassName("hide");

    //loop through the collection
    for (var i = 0; i < collection.length; i++) {//begin for loop

        //hide the element
        collection[i].style.display = "none";

    }//end for loop

}//end function
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement