2 Replies - 533 Views - Last Post: 26 February 2012 - 07:52 PM

#1 Tsalagi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-February 09

Displaying Data from one element to another

Posted 25 February 2012 - 08:35 AM

This seems to be quite simple but I'm having a heck of a time getting the solution to work.

I want to send the data from one paragraph located in one section of a page to another section after an element is clicked.

This is strictly esthetics and doesn't have to do with functionality.

Here are the html elements.

I've truncated them for easy readability. If you need the entire block, I'll post it.
 echo '<p class="desc_link">';
       echo '<a class="desc_show more" rel="' . $image_title . '" href="#desc">Description</a></p>';
       echo '<p class="attach_desc">'.$description;
       echo '</p></li>';

If the second line above is clicked, I'd like the third line to be passed to a div with an id of ajax on the same page.

I am using this code to try and accomplish this but it isn't working.

	
$("a.desc_show").click(function() {
var show_desc = $('p.attach_desc').html();
$('#ajax').html(show_desc);
return false;
});
});


Here is another block of jQuery that I'm using on the same page. The block of html above is located on another page that is loaded by this block. This may be a factor in causing my other block not to work.

	$(document).ready(function(){
	$.ajaxSetup({cache:false});
	$("a.btn").click(function(){
		var import_link = $(this).attr("href");

		$("#portfolio").html("loading...");
		$("#portfolio").load(import_link);
		return false;
	});


Thanks in advance for any suggestions on how to accomplish this. If my code is improper, I would not be surprised as I am a novice at jQuery.

Is This A Good Question/Topic? 0
  • +

Replies To: Displaying Data from one element to another

#2 Tsalagi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-February 09

Re: Displaying Data from one element to another

Posted 25 February 2012 - 08:45 AM

By the way, I'm receiving no errors in the error console.
Was This Post Helpful? 0
  • +
  • -

#3 hiddenghost  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 39
  • View blog
  • Posts: 621
  • Joined: 15-December 09

Re: Displaying Data from one element to another

Posted 26 February 2012 - 07:52 PM

I have no idea of how to do this with jQuery.

I'm also not sure if you would actually need ajax to do this.

Here is a possible solution only using the DOM.

<html>
<body>
<p>Let's remove some text here by clicking the red text:</p>
<p id="sender" style="color: red">Here's some text to move.</p>
<p>And move it here:</p>
<p id="receiver">here's some text to replace.</p>
<script type="text/javascript">
var sender = document.getElementById("sender");
function sendIt(){
    var passData = document.createTextNode("Moved text =" + sender.firstChild.nodeValue);
    var receiver = document.getElementById("receiver");
    receiver.removeChild(receiver.firstChild);
    receiver.appendChild(passData);
    sender.removeChild(sender.firstChild);
}
sender.addEventListener("click", sendIt, false);
</script>
</body>

</html>



It doesn't do any crazy ajax stuff, but it gets the job done.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1