Alon Shmiel
Alon Shmiel

Reputation: 7121

change div content by clicking an image

I have this div:

<div class="main_mark">
    <img src="/assets/welcome_main.png" alt="main" class="main_mark_image" />
</div>

I want the next thing: when the user click the image, this div will changed to:

<div class="main_mark">
    <embed width="420" height="345" src="http://www.youtube.com/v/XjR-4lbK1mI" type="application/x-shockwave-flash">
    </embed>
</div>

so in my javascript, I have tried to do something like:

$(".main_mark_image").click(function () {
    $("#main_mark").innerHTML = "<embed width=420 height=345 src=http://www.youtube.com/v/XjR-4lbK1mI type=application/x-shockwave-flash></embed>";
});

but it doesn't change anything..

any help aapreciated!

Upvotes: 0

Views: 630

Answers (5)

cameronjchurch
cameronjchurch

Reputation: 410

use a combo of both @sdespont and @kmd97

$(".main_mark_image").click(function () {
// Changed selector to class
$(".main_mark").html("<embed width=420 height=345 src=http://www.youtube.com/v/XjR-4lbK1mI     type=application/x-shockwave-flash></embed>");
});

Upvotes: 1

sjain
sjain

Reputation: 23344

Try:

$(".main_mark_image").click(function () {

    $(".main_mark").html = "<embed width=420 height=345 src=http://www.youtube.com/v/XjR-4lbK1mI     type=application/x-shockwave-flash></embed>";
    });

Upvotes: 1

sdespont
sdespont

Reputation: 14025

Use html function : http://api.jquery.com/html/

$(".main_mark_image").click(function () {
    $("#main_mark").html("<embed width=420 height=345 src=http://www.youtube.com/v/XjR-4lbK1mI type=application/x-shockwave-flash></embed>");
});

Upvotes: 1

jmorc
jmorc

Reputation: 570

main_mark is a class not a id. Use .main_mark

Upvotes: 1

Dineshkani
Dineshkani

Reputation: 3015

$(".main_mark").html("Your code")instead of $("#main_mark").innerHTML

Upvotes: 1

Related Questions