Reputation: 29514
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??????
});
Upvotes: 434
Views: 764748
Reputation: 81
Syntax:
$(selector).text()
returns the text content.
$(selector).text(content)
sets the text content.
$(selector).text(function(index, curContent))
sets text content using a function.
Source: https://www.geeksforgeeks.org/jquery-change-the-text-of-a-span-element/
Upvotes: 8
Reputation: 1785
The solution that work for me is the following:
$("#spanId").text("text to show");
Upvotes: 6
Reputation: 386
You are using jQuery(document).ready(function($) {}
means here you are using jQuery
instead of $
. So to resolve your issue use following code.
jQuery("#submittername").text(submitter_name);
This will resolve your problem.
Upvotes: 21
Reputation: 17544
You're looking for the wrong selector id:
$("#submitter").text(submitter_name);
should be
$("#submittername").text(submitter_name);
Upvotes: 17
Reputation: 625007
You can do:
$("#submittername").text("testing");
or
$("#submittername").html("testing <b>1 2 3</b>");
Upvotes: 860