Thursday, April 5, 2012

how to set a value for a span using JQuery


How to set a value for a span using JQuery..



For example… Below is my span




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



in my JQuery code…




<script type="text/javascript">
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??????
});


Source: Tips4all

3 comments:

  1. You can do:

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


    or

    $("#submittername").html("testing <b>1 2 3</b>");

    ReplyDelete
  2. You're looking for the wrong selector id:

    $("#submitter").text(submitter_name);


    should be

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

    ReplyDelete
  3. 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.

    ReplyDelete