Jump to content

Recommended Posts

I am having trouble getting the slideToggle function to work. i need to click on a href with a class and i want it to open a div underneath. i tried using the next() function, but that didnt work. So what the function does now is when i click the link it will slidetoggle all the contact div. I want it to open just the next div with the class of contact. 

 

 

PHP Function 


<div class="posting">
	<div class="one columns">
		'.$image.'
	</div>
	<div class="fifteen columns">
		<a href="#" class="contactlink"><div class="posttitle">'.stripslashes($mainRow['book_title']).'</div></a>
		<div class="postdesc">'.stripslashes($mainRow['book_desc']).'</div>
		<br>
		<div class="three columns"><div class="postprice">$ '.stripslashes($mainRow['book_price']).'</div></div>
		<div class="three columns"><div class="postclass">'.stripslashes($mainRow['book_class']).'</div></div>
		<div class="three columns"><div class="postcondition">'.stripslashes($mainRow['book_condition']).'</div></div>
	</div>
</div>
<div class="clear"></div>
<hr>
<div class="contact" style="display:none;">
	<form action="">
		<input type="text">
		<input type="text">
		<input type="text">
	</form>
</div>

jQuery Function

$(document).ready(function() {
  $('.contactlink').click(function() {
     $(".contact").slideToggle('fast'); // Toggle dd when the respective dt is clicked
  });
});

Link to comment
https://forums.phpfreaks.com/topic/278915-slidetoggle-help/
Share on other sites

Since your elements do not share a parent and they are not directly related, you would need to add either an id or a reference to link both of the elements (e.g. give the link an id "contactlink_id_1" and the div "contact_id_1").

 

Otherwise, you would have to loop through the entire document and check if the contact element is after the element that fired the event (which is not optimal)..

Link to comment
https://forums.phpfreaks.com/topic/278915-slidetoggle-help/#findComment-1434782
Share on other sites

Let's say you have this html code <a href="#" class="contactlink" id="my_link_id_1">, you can use jquery to extract the id as the following

$('.contactlink').click(function(){
   var id = this.id;
   id = id.split('_');
   id = id[id.length - 1];
   alert(id); // You can use $("#contact_id_"+id).slideToggle('fast'); here
});









Edited by nogray
Link to comment
https://forums.phpfreaks.com/topic/278915-slidetoggle-help/#findComment-1434907
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.