josh
josh

Reputation: 839

jquery change text in div

Right now the div text is being changed to "text" I need it to be changed to the "data-text" from the link.

<a href="1884.html" class="brieflink" data-src="article.jpg" data-text="text4">Brief 4</a>

<div id="brieftext"><p>Text to be replaced</p></div>

$("a.brieflink").bind("mouseover", function() {
    $("div#brieftext").text("text", $(this).data("text"));
});

Upvotes: 1

Views: 11739

Answers (3)

user719367
user719367

Reputation:

$("div#brieftext").text($(this).attr("data-text"));

I have been learned:

$("div#brieftext").text($(this).data("text"));

will also work after 1.4, thanks @Rocket.

Upvotes: 8

Phillip Kovalev
Phillip Kovalev

Reputation: 2497

$.text() takes one argument only. Try:

$("div#brieftext").text( $(this).data("text") );

Upvotes: 1

gen_Eric
gen_Eric

Reputation: 227310

.text() only takes 1 parameter.

$("div#brieftext").text($(this).data("text"));

Upvotes: 2

Related Questions