RAVITEJA SATYAVADA
RAVITEJA SATYAVADA

Reputation: 2571

how to assign value of a div to another div

I am new to jquery . I wrote small piece of code

<div id="tablediv"><table><tr><td><h2>Select SalesPerson</h2></td><td id="heading"><h3>&nbsp;Click Here&nbsp;</h3></td></tr>
    <tr><td></td><td id="101" class="options">12304</td></tr>
    <tr><td></td><td id="102" class="options">12305</td></tr>
    <tr><td></td><td id="103" class="options">12306</td></tr>
    <tr><td></td><td id="104" class="options">12307</td></tr>
</table></div>
</center>
<div id="imagediv"><img src="" id="photo" alt="No Image Found" width="150" height="150"/></div>

And I used the following jquery code:

$(document).ready(function(){
    $('td.options').hide();
    $("#heading").click(function(){
        $('td.options').toggle();
    });
    $("td.options").hover(function(){
        var imgsrc = $(this).attr('id')+".jpg";
        $("#photo").attr('src',imgsrc);
    });
    $("td.options").click(function(){
         // $("td.options").val($("#heading").val);
         //alert($('td.options').text());
         //alert($(this).parent().attr('id'));
         //alert($(this).parents('.class'));
         $('td.optiodns').hide();
     });
 });

Now when I click any on of the options (12304/12305/12306/12307), that value has to replace the content of heading tag. How to do it?

Upvotes: 0

Views: 329

Answers (1)

Cyclonecode
Cyclonecode

Reputation: 30061

You guess you are looking for the html function:

$("#heading").click(function() {
  $('td.options').toggle();
});
$("td.options").hover(function() {
  var imgsrc = $(this).attr('id')+".jpg";
  $("#photo").attr('src',imgsrc);
});
$("td.options").click(function() {
  $("#heading").html($(this).html());
  $('td.optiodns').hide();
});

You can read about the text() and html() functions here jquery api - html

Upvotes: 2

Related Questions