I can't even get $ () text to work correctly. Prints a massive line of code instead

I installed the test, so I can start using jQuery in the cakePHP environment, but before running I ran into a problem.

I also have a tweeter bootstrap, but when I had this problem, I turned off everything to make sure it wasn’t. This is not true.

I am testing this in Chrome and Waterfox.

When I tried $('#test').html('Hello');, I got nothing. So I tried to warn something using the following:

$(document).ready(function() {

    $('#test').click(function() {
        alert($('#test').text);
    });
});

and

<span id="test">test span</span>

Which gives me the result:

function (a){return f.access(this,function(a){return a===b?f.text(this):this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a))},null,a,arguments.length)}

Can someone please tell me what the hell is it please and why I didn’t get a “test space”. Thank:)

+5
source share
8 answers

'text' - ,

alert($('#test').text());
+10

jQuery.text() - , . :

var a = $('#test').text(); // getter
$('#test').text(a);        // setter

: jQuery.html(), HTML.

+5

.text()

+1

text() - jQuery; , text():

alert($('#test').text());
+1

.text() . ,

alert($('#test').text());
0

, :

$('#test').text("Hello");

, . . :

$('#test').val("Hello");
0

"", . '()'. , JavaScript, .

, , .

0

, alert an object, .toString() (Doc) object, function object .

MDN

window.alert();

message - , , , , .

,

alert($.fn.text.toString())

, .

Because when .toString()called into a function object, this definition is returned. You need to call the function, like any other, adding ()with the name of the function.

Since everyone else has already said you should call him like alert($('#test').text());

0
source

All Articles