user3012804
user3012804

Reputation: 81

changing the text of asp label

I am trying to change the text of label using jquery

function openMe(p_whoIs) {
          var $img = $(p_whoIs.alt).clone();
          $("#Label1").text($img);
          $("#dialog").dialog("open");
      }

now when i give the any value in text of label it change the value like

$("#Label1").text("img");

and var $img is also working fine i have checked it with other control but when i assign this value to label text it display [object object] not the variable $img value. So how to do that??

Upvotes: 0

Views: 430

Answers (3)

Kamlesh
Kamlesh

Reputation: 529

Put asp label control in div tag then use following code

$("#DivID span").html($img.val());

Upvotes: 0

Abhitalks
Abhitalks

Reputation: 28387

That is because $img is a jQuery object, not string. You need to extract some string value out of this object, like src or id or..

It seems you are trying to extract the alt property:

var altText = $(p_whoIs).attr("alt");
$("#Label1").text(altText );

Upvotes: 2

tjcertified
tjcertified

Reputation: 704

You need to pull the text from a property of $img, whatever that variable is. If it is an HTML input, then in jQuery, you would use:

$img.val()

so that your code from above would be:

function openMe(p_whoIs) {
      var $img = $(p_whoIs.alt).clone();
      $("#Label1").text($img.val());
      $("#dialog").dialog("open");
  }

This is as close as I can get without knowing what the $img object is.

Upvotes: 0

Related Questions