简体   繁体   中英

Hide dynamic div element in javascript and/or html

I'm kind of new at this so bear with me. I am trying to hide a specific dynamic div element (it's a catalog) out of a list of 6 elements (catalogs) but not having much luck. To be specific, catalogid="3" needs to be hidden on the page yet still remain active. If the exact url for that catalog is pasted into the browser, the catalog should be accessible. Basically, it is going to be a hidden catalog only given to specific customers in order to buy specific products.

Here is the HTML:

<span catalogLink='index.html?action=courseBrowse&CatalogID=${CatalogID}' style="color:#fff">${Name}</span>

And here is the Java script code:

 location.href =getHostingHTML()+"?action=courseBrowse&CatalogID="+catalogID;

Question: Can I just put a snip-it of code under either of those lines that would simply hide catalog 3 after execution?

I think you should try to give this css attribute to the span element.

span {
  display:none;
}

this will do the trick

span {
  display:none;
}

however, this will hide every span in your entire website. You might want to add a class to the specific span class you would like to hide:

<span class="hide-me" catalogLink='index.html?action=courseBrowse&CatalogID=${CatalogID}' style="color:#fff">${Name}</span>

<style type="text/css">

.hide-me{
   display:none;
}

</style>

additionally you could do this as well

<span catalogLink='index.html?action=courseBrowse&CatalogID=${CatalogID}' style="color:#fff; display:none;">${Name}</span>

Try this:

<span id='myspan' catalogLink='index.html?action=courseBrowse&CatalogID=${CatalogID}'style="color:#fff">${Name}</span>

I recomend to add an Id to your span, and then dinamically, in your javascript call the following:

document.getElementById("myspan").style["display"] = "none";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM