hi,
i will like to seek expertise advice on some javascript programming for my blog.
i'm using blogger and sometimes i will post quite a lot of photos of my figures thus making the page very long.
blogger doesn't come with the option to jump to another page within the same post so i will like to learn how to hide the content instead.
for example,
paragraph 1
click here to continue reading
paragraph 2
paragraph 3
paragraph 4
click here to hide
so what i want is by default only paragraph 1 will show on the blog, when visitors click on "click here to continue reading" paragraph 2 to 4 will show up. at the bottome will be "click here to hide"
any advices for this is greatly appreciated.
Use div or span to segregate the parts.
E.g.
<div id="para1">
paragraph one stuff
<a href="javascript:doHide();doShow(2);">Next</a>
</div>
<div id="para2" style="display: none;">
paragraph two stuff
<a href="javascript:doHide();doShow(3);">Next</a>
</div>
<div id="para3" style="display: none;">
paragraph three stuff
</div>
<script language="Javascript">
function doHide() {
var x=document.getElementsByTagName("div");
for (y = 0; y < x.length; y++) {
if (x[y].id.indexOf("para") == 0) {
x[y].style.display = "none";
}
}
}
function doShow(myid) {
if (document.getElementById("para" + myid)) {
document.getElementById("para" + myid).style.display = "";
}
}
</script>
since we are on the topic of javascript/java...anyone knows of any good free webhosting server that allows the use of *.java files?
Originally posted by GIB:Use div or span to segregate the parts.
E.g.
<div id="para1">
paragraph one stuff
<a href="javascript:doHide();doShow(2);">Next</a>
</div>
<div id="para2" style="display: none;">
paragraph two stuff
<a href="javascript:doHide();doShow(3);">Next</a>
</div>
<div id="para3" style="display: none;">
paragraph three stuff
</div>
<script language="Javascript">
function doHide() {
var x=document.getElementsByTagName("div");
for (y = 0; y < x.length; y++) {
if (x[y].id.indexOf("para") == 0) {
x[y].style.display = "none";
}
}
}
function doShow(myid) {
if (document.getElementById("para" + myid)) {
document.getElementById("para" + myid).style.display = "";
}
}
</script>
i tried it on a text file and converted it to a html it works. but when i tried on blogger it doesn't work. :-(
the hide function also doesn't work. :-(
below is my coding, please help to look through it and advice me on the coding for the show and hide.
----------------------------------------------------------------------------------------------------------
<div id="para1">
paragraph one stuff <- to be displayed always
<a href="javascript:doHide();doShow(2);">Click here to read more</a>
</div>
<div id="para2" style="display: none;">
paragraph two stuff <- to hide until until users click to open
</div>
<script language="Javascript">
function doHide() {
var x=document.getElementsByTagName("div");
for (y = 0; y < x.length; y++) {
if (x[y].id.indexOf("para") == 0) {
x[y].style.display = "none";
}
}
}
function doShow(myid) {
if (document.getElementById("para" + myid)) {
document.getElementById("para" + myid).style.display = "";
}
}
</script>
where to put the "click here to hide"?
<html>
<body>
<div>
paragraph one stuff <- to be displayed always
<a href="javascript:doShow(2);">Click here to read more</a>
</div>
<div id="para2" style="display: none;">
paragraph two stuff <- to hide until until users click to open
paragraph three stuff <- to hide until until users click to open<br>
paragraph four stuff <- to hide until until users click to open<br>
<a href="javascript:doHide(2);">Click here to hide</a>
</div>
</body>
</html>
<script language="Javascript">
function doHide(myid) {
if (document.getElementById("para" + myid)) {
document.getElementById("para" + myid).style.display = "none";
}
}
function doShow(myid) {
if (document.getElementById("para" + myid)) {
document.getElementById("para" + myid).style.display = "";
}
}
</script>
THANKS GIB! it works! ^_^
but only on notepad but not on blogger. any ideas how to slove it?
I just saw some other blog and they mentioned something about Javascript on blogger.
If you have convert line breaks set to "YES" then you have to put in the javascript codes without carriage returns else you get br on all the new lines and that will break the code.
When publishing, u will get an error saying "tag is not allowed", check the box that says stop reporting errors for this post and publish again. It should work now.
thanks GIB but i still can't get it to work. i have already taken out all the carriage returns.
<div>
paragraph one stuff <- to be displayed always
<a href="javascript:doShow(2);">Click here to read
more</a>
</div>
<div id="para2" style="display: none;">
paragraph two stuff <- to hide until until users click to
open
<a href="javascript:doHide(2);">Click here to
hide</a>
</div>
<script language="Javascript">
function doHide(myid) {if (document.getElementById("para" + myid)) {document.getElementById("para" + myid).style.display =
"none";}}
function doShow(myid) {if (document.getElementById("para" + myid)) {document.getElementById("para" + myid).style.display = "";}}
</script>
I have just tested and mine worked. Just make sure <script> to </script> is in one line.
GIB it works!!!! THANKS SO MUCH!!! already implemented it on my blog. the <script> to </script> must be in one line.
i must remember to treat u lunch next time we meet. ^^
anyway can i bother u for one last thing? when people click to read more then click hide, the page stays at the same place. is it possible to code it so that it go back to the top of paragraph one?
Change this <a href="javascript:doHide(2);">Click here to hide</a> to
<a href="javascript:doHide(2);doScroll(1);">Click here to hide</a>
and the first div put id="para1".
Then inside the <script></script> add another function called doScroll.
function doScroll(myid) {
if (document.getElementById("para" + myid)) {
document.getElementById("para" + myid).scrollIntoView(true);
}
}
Thanks again GIB! it works.
if u need anything from me just let me know. i owe u one.
aiseh man.. yuan lai GIB is java pro.. i thot he put up jokes nia.. hahaha..
GIB, i have already credited $6969 into your account.