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?
JavaScript
x
21
21
1
$$$<ul id = "myid"class = "listbranch">
2
<li>Битола</li>
3
<li>Скопје</li>
4
<li>Охрид</li>
5
<li>Прилеп</li>
6
<li>Ресен</li>
7
<li>Гостивар</li>
8
<li>Куманово</li>
9
<li>Гевгелија</li>
10
<li>Штип</li>
11
<li>Велес</li>
12
<li>Пробиштип</li>
13
<li>Тетово</li>
14
<li>Кочани</li>
15
<li>Валандово</li>
16
<li>Струмица</li>
17
<li>Крива Паланка</li>
18
<li>Кавадарци</li>
19
<li>Неготино</li>
20
</ul>$$$
21
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,
JavaScript
1
3
1
//hide the element with the hide class
2
$(".hide").hide();
3
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:
JavaScript
1
2
1
<span>$$$</span>
2
CSS:
JavaScript
1
11
11
1
span{
2
display:"none";
3
}
4
5
/* use this class if you don't want to hide all span tags*/
6
.hide{
7
8
display:"none";
9
10
}
11
If you want hide the $$$ using plain JavaScript? You can try the following:
JavaScript
1
27
27
1
//Call the hide function,
2
//the $ must be escaped so that regexp will pick up all three of them
3
hide(/$$$/);
4
5
function hide(text) {//begin function
6
7
//create a new RegExp object with the global replacement flag
8
var search = new RegExp(text,"g");
9
10
11
//wrap the $$$ with a span element
12
document.body.innerHTML = document.body.innerHTML.replace(search, "<span class='hide'>$$$$$$</span>");
13
14
15
//store the collection of elements with the hide class
16
var collection = document.getElementsByClassName("hide");
17
18
//loop through the collection
19
for (var i = 0; i < collection.length; i++) {//begin for loop
20
21
//hide the element
22
collection[i].style.display = "none";
23
24
}//end for loop
25
26
}//end function
27