Post by Alan Vende on Feb 16, 2017 21:26:36 GMT -8
I am creating a plugin over on a test forum of mine, and I am running into a few problems with a piece of code that I'm attempting to use.
I wanted to have a button in the plugin (which I have accomplished) and I wanted that button to show/hide a div.
I searched Google and found a few pieces of code, and the one below seems to be the closest to what I want:
My HTML is
Is there a way to make it so the content is hidden on page load and then you have to click the button to toggle it open and then closed again?
I had changed the code from the $("p").toggle(); to $(".ppaffiliates").toggle(); because I wanted the div to toggle, not just the paragraphs within the div, and it seems to have worked, just the opposite of how I envisioned it It's showing on page load and showing/hiding when you click the button. I wanted it to be hidden on page load and then you click the button for it to show/hide. Does that make sense? The functionality I want is accomplished here, and I used the code initially to see how I wanted it to work, but now I'm attempting to search for other options when I bring this live on my main forum. I didn't want to look like I was copying anyone; I just wanted to see how it worked so when I searched for a code I knew what I was looking for.
Thanks so much for your help/insight. I've been trying to research this for the past three hours with minimal success...
I wanted to have a button in the plugin (which I have accomplished) and I wanted that button to show/hide a div.
I searched Google and found a few pieces of code, and the one below seems to be the closest to what I want:
// JS from https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_show
$(document).ready(function(){
$("button").click(function(){
$(".ppaffiliates").toggle();
});
});
My HTML is
<div class="affiliatebutton">
<button>Click to view our affiliate code and rules</button>
</div>
<div class="ppaffiliates">
<div class="ppaffrules">
<div align="center" class="ppaffcodecontainer">
<p class="ppaffcodetitle" align="center">Our Affiliate Code</p>
<p><textarea readonly="true" onclick="this.select()" style="width: 1200px; height: 15px; font-size: 8pt;"><a href="http://psychic-psyghtings.proboards.com/" target="_blank" title="Psychic Psyghtings"><img src="http://storage.proboards.com/2837905/i/9OmzvIlu49a6OB8UjnKV.jpg" alt="Psychic Psyghtings" /></a></textarea></p>
</div>
<div align="center" class="ppaffrulestext">
<p align="center" class="ppafftextheading">Our Affiliate Rules</p>
<p align="center" class="ppafftextbody">Like many other forumes, ours has rules governing our affiliation with other forums. Please take a minute to review them by clicking the button below.</p>
<div align="center"><a href="http://psychic-psyghtings.proboards.com/thread/978/affiliate-psychic-psyghtings"><button>Psychic Psyghtings Affiliate Rules</button></a></div>
</div>
</div>
</div>
Is there a way to make it so the content is hidden on page load and then you have to click the button to toggle it open and then closed again?
I had changed the code from the $("p").toggle(); to $(".ppaffiliates").toggle(); because I wanted the div to toggle, not just the paragraphs within the div, and it seems to have worked, just the opposite of how I envisioned it It's showing on page load and showing/hiding when you click the button. I wanted it to be hidden on page load and then you click the button for it to show/hide. Does that make sense? The functionality I want is accomplished here, and I used the code initially to see how I wanted it to work, but now I'm attempting to search for other options when I bring this live on my main forum. I didn't want to look like I was copying anyone; I just wanted to see how it worked so when I searched for a code I knew what I was looking for.
Thanks so much for your help/insight. I've been trying to research this for the past three hours with minimal success...