Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a value for a span using jQuery

Tags:

jquery

How to set a value for a <span> tag using jQuery…

For example…

Below is my <span> tag:

<span id="submittername"></span> 

In my jQuery code:

jQuery.noConflict();      jQuery(document).ready(function($){      var invitee = $.ajax({         type: "GET",         url: "http://localhost/FormBuilder/index.php/reports/getInvitee/<?=$submitterid;?>",         async: false     }).responseText;      var invitee_email=eval('(' + invitee + ')');     var submitter_name=$.map(invitee_email.invites, function(j){          return j.submitter;     });              alert(submitter_name); // alerts correctly      $("#submittername").text(submitter_name); //but here it is not working  WHy so?????? }); 
like image 607
useranon Avatar asked Sep 29 '09 10:09

useranon


People also ask

How do you value a span?

jQuery: Set a value in a span Set a value in a span using jQuery. JavaScript Code: $(document). ready(function(){ $('#button1').

How do I set the value of a element in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.

Can spans have values?

a span doesn't have a value attribute.


1 Answers

You can do:

$("#submittername").text("testing"); 

or

$("#submittername").html("testing <b>1 2 3</b>"); 
like image 125
cletus Avatar answered Sep 21 '22 05:09

cletus