John Knutson John Knutson - 5 months ago 10
jQuery Question

Why can't I display my text with Jquery

I've inherited this Laravel PHP app with some Javascript and I'm learning these
.technologies as I work to enhance it. I've got this bit of code that I need to change, but I really don't understand it. Any help you can give to solve my problem and improve my understanding would be most welcome.

The code in question is executed when a

<div>
#tweetContainer
, a class defined in the CSS. on a web page is clicked. As it stands, the code presents a pop-up with the text from the
<div>
. I want to change it so that it uses the string
post.data
.

I don't understand what the statements after the
{
are. I've tried replacing the first one with various forms of
post.data
but haven't got anything to work.

$("#itemContainer .listview_tile:last").click(function(){
$("#tweetContainer").val($(this).text());
$("#loading").toggleClass('displayTable');
$("#loading").fadeTo("fast", 0.95);
});


The
click()
function appears to be part of Jquery.
Why does this work and what can I do to make it do what I need?

Answer

As it stands, the code presents a pop-up with the text from the . I want to change it so that it uses the string post.data.

If I understand correctly, you want the value of post.data to be set as the text of #tweetContainer.

You need to use this :

$('#tweetContainer').text(post.data);

val() is use to set and get the value attribute of an element, if you want to change the content of a div for example, you need to use text() .

Comments