![]() |
how to open independently 2 buttons with slide effect (solved)
hi
first of all i wanted to say that i have no idea of coding with any language, and that the code that i use was found from searching. i needed for my blog a hidden-toggle-slide effect for my text. i was trying to copy-paste from tutorials the code but most times that didnt work, when i found the code i was looking for i tested it and found this problem. when you post 1 button it works fine, but when you post 2 it has the problem that it opens both of the hidden text (sorry about talking this much but it's the first time i am asking for help in this forum, and i am not sure how to explain my problem). this is the code that i am using Code:
<!doctype html>and if there are any questions please ask them i ll help as much i can thank you in advance (if i posted it in the wrong place i apologise) |
There's a few ways to do what you're doing.
The code you posted uses a javascript framework - basically a box of tools - called jQuery. Being familar with jQuery selectors will make it easier for you to understand what's going on in the code and tweak it to behave how you want. The problem that you're having is caused by the fact that your code is selecting ALL the paragraph elements. You don't want that: you just want to affect a particular paragraph. One way to get around it is to give your buttons and your paragraphs ID tags. This will let you tie a particular button to a corresponding paragraph: Code:
<p id="paragraph_one">Hello World</p>Code:
$("#button_one").click(function () {Now, that's fine - but you've probably noticed that if you've got more than one paragraph-and-button combination on your page, you're going to have to copy that javascript code for each one, like so: Code:
$("#button_one").click(function () {There are a couple of ways to do this. One way is to use jQuery's next() function to tell the button that it should be controlling the paragraph right next to it: Code:
$("button").click(function () { // when any button is clickedCode:
$("button").click(function () {Any help? |
thank you very much :D works like a charm :D
i used the first way you gave because the others where too complicated for me xD, but i ll look into the rest two codes later :). Finished Example |
| All times are GMT +1. The time now is 11:21 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.