Reputation: 641
I have some simple code below:
<script>
$(function() {
$("h1").click(function(){
console.log((this));
$("p").toggle();
});
});
</script>
</head>
<body>
<h1>test</h1>
<p>If you click test, I will toggle.</p>
</body>
If I click on test I can toggle the visibility of the p tag. At the same time I am writing <h1>test</h1>
to the console. What I want is to write the word test only to the console. How do I do that? Nothing I tried works.
Thanks, Jim
Upvotes: 0
Views: 71
Reputation: 4389
Use the .text() function, it will give you the text only.
$(function() {
$("h1").click(function(){
console.log($(this).text());
$("p").toggle();
});
});
You can see the working code here.
Upvotes: 3
Reputation: 22241
Replace:
console.log((this));
With
console.log($(this).text());
Upvotes: 1