I’m trying to learn jquery, so I’m attempting to write a script that’ll hide most things on a page, leaving (for now) only the paragraphs.
(function() {
var all = $("*");
all.hide();
var paragraphs = $("p");
paragraphs.show();
})();
That is the code I have now, but it doesn’t work. It hides everything, but it doesn’t show the paragraphs afterwards. What am I doing wrong?
Here is one solution for a start:
Read it as: in
<body>element find all elements that are not<p>.I suspect your markup is quite simple with minimum of nested elements, e.g.
Otherwise, as noted in the other answers (and comments), you should consider if your
<p>elements do have non-<p>parents. In such cases nested paragraphs might remain invisible.