I would like to know if it is possible, and if yes. Please, someone tell me how or just point me to a tutorial. Thanks a lot.
Asked
Active
Viewed 1,786 times
-1
-
You shouldn't use regular expressions to process HTML: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags. Instead you should use the built in DOM functions in JavaScript. – murgatroid99 Sep 26 '12 at 04:41
-
i just want to use this while rendering old items, not while posting new one. And this is the problem I'm facing. – Beshoy Sep 26 '12 at 04:53
-
I don't understand your comment. JavaScript on a page can access any of the DOM elements already on the page. – murgatroid99 Sep 26 '12 at 05:05
-
@murgatroid99 In this [page](http://dynamic-javascript.blogspot.com/) you'll find what i'm talking about, I just need to show the part that displays post content and remove the two sections that contains ads. But the problem is that there are a hell lot of those posts which can't be done manually. So, I'm trying with your help to create a JS script to hide those to sections. That's it, hope it is clear now :) – Beshoy Sep 26 '12 at 05:29
-
I understand that you are trying to hide DOM elements in a page. I'm just trying to get you to understand that whenever possible you should avoid using regular expressions to process HTML. And in this case it looks like that *is* possible: you can access the DOM with javascript (`document.body`) and then process it as an HTML tree, which is better than processing it as a string. – murgatroid99 Sep 26 '12 at 06:14
-
@murgatroid99 aha now I get what you mean, thanks :) – Beshoy Sep 26 '12 at 06:46
2 Answers
1
yeah only with dom functions
document.getElementById("p1").style.visibility="hidden";
like Ref
<html>
<head>
<script>
function displayResult()
{
document.getElementById("p1").style.visibility="hidden";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<input type="button" onclick="displayResult()" value="Hide paragraph" />
</body>
</html>

swemon
- 5,840
- 4
- 32
- 54
-
What if there is no ID? like in the two ad sections on this test page? [link](http://dynamic-javascript.blogspot.com/) – Beshoy Sep 26 '12 at 04:55
-
This is what I'm trying to do, to get rid of those two Ad sections on OLD posts. – Beshoy Sep 26 '12 at 04:56
-
Not sure but, if it is for your own site and you're hosting it for free, it could be suspended due to breach of rules if you'd do that. – Fabrício Matté Sep 26 '12 at 04:58
-
In the page on the other end of that link there is a table with three rows. 1st is an ad, 2nd is the content and the 3rd is an ad. If this is always the structure you can keep the 2nd row and hide the rest – Vaughan Sep 26 '12 at 05:12
-
You say it there is no ID, but there is something like that dom.getelementsbytagname, dom.getelementsbyclassname to access this object in javascript field. It depends upon u. – swemon Sep 26 '12 at 05:13
-
@FabrícioMatté I think blogger doesn't care a bout those small changes :) – Beshoy Sep 26 '12 at 05:23
-
-
@swemon Yea, but here in this table, it doesn't have any "ID" or "ClassName" to depend upon. – Beshoy Sep 26 '12 at 05:25
-
if table has id, then document.getElementById("myTable").rows[0].style.visibility="hidden"; but this does not shrik table. – swemon Sep 26 '12 at 05:29
-
0
Here is my shot:
The table you want seems to be in a div which is within a div with class=post-body. Something like this:
<div class="post-body">
<div dir="ltr">
<table>
<tr><td>Ad</td></tr>
<tr><td>Content</td></tr>
<tr><td>Ad</td></tr>
</table>
</div>
</div>
I used jQuery to select all rows but the second one and hide them like this
$(document).ready(function(){
$('div.post-body > div > table tr:not(:nth-child(2))').hide();
})
jsfiddle here: http://jsfiddle.net/qx2GY/

Vaughan
- 162
- 3
- 9