Javascript Wildcard with jQuery
One of the developers I work with came up with a handy bit of JavaScript that uses a wildcard to look for a div that has “div-comment-” in its ID. It then does a display none on them. The handy thing about this basic bit of script is that it can be used across a website to edit the css.
Remember for this to work you will need jquery to be called in within the head of your page. This can be done be done by downloading jquery from here and using code like this in your page head…
| <script language=”JavaScript” type=”text/javascript” src=”https://yourwebsite.com/jquery-1.2.6.js”></script> |
Example Use
Imagine you have a series of div’s that are displayed on a page such as comment boxes. Those div’s have ID’s of div-comment-1, div-comment-2, div-comment-3 and so on. You want to click
So here’s the JavaScript you put in the head of the page.
| <script> function MyFunction() { $(”div[id*='div-comment-']“).css(’display’, ‘none’); } </script> |
And the link will look like this..
| <a href=”javascript: MyFunction();”> |
That link could be in a text format or in the form of a button/image.
Essentially this handy bit of JavaScript can be used endlessly across a website to give the user more control over the look and appearance of the page.