Reputation:
I have a database with two tables, each has three rows and both are connected by id. i executed them in .php so that each row in table_1(question) has its replies in table_2(answers).
Ans now i tried to put a SLIDEUP/SLIDEDOWN function for the answers triggered by buttons. But unfortunately something is missing...
My Code as follows::
<div id="a" name="a">
<small><p><?php echo $row2["date"]; ?></p></small>
<p><B><big><font color= #ba4a00> A:</font></B></big> <small><?php echo $row2["answer"]; ?></small></br></p>
</div>
<button class="btn1">Slide up</button>
<button class="btn2">Slide down</button>
<script type='text/javascript'>
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".btn2").click(function(e){
e.preventDefault();
$('[name="a"]').slideDown();
$(this).parent().$('[name="a"]').slideDown();
$(this).hide();
});
$(".btn1").click(function(e){
e.preventDefault();
$(this).parent().$('[name="a"]').slideUp();
$(this).hide();
});
});
</script>
Upvotes: 0
Views: 29
Reputation: 639
The jQuery functions usually return a jQuery object so you can easily chain the actions. In your code you call$(this).parent().$('[name="a"]').slideDown()
which is actually a kind of nonsence. The $('[name="a"=')
does not belong there.
I'd suppose you want to call the $('[name="a"]').slideDown()
part to slid the contents of the div
down. If you want to do this, then the call to the parent()
function seems to be unnecessary.
Upvotes: 0
Reputation: 1075209
If you open your web console, you'll see an error there about trying to call undefined
as a function, because of this:
$(this).parent().$('[name="a"]').slideDown();
$(this).parent()
returns a jQuery object. jQuery objects don't have a $
property.
You probably meant
$(this).parent().find('[name="a"]').slideDown();
Side note: From the code, it seems likely to me that this structure containing the div and buttons is repeated more than once on the page. If so, you need to remove the id="a"
on the div, as you cannot have the same ID on more than one element.
Upvotes: 1