-2

I know its a basic question but I have tried to out put the username from this jquery code in a html div tag, but no success so far, I wonder how to call it and display it in a div tag?

Source:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>

<script type="text/javascript"> 
    var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "Title",
                debug: false

    });
</script>

Html Body:

<div id="1" style="font-weight: bold;">thisUserAccount</div>
Dreamer64
  • 923
  • 2
  • 13
  • 30
  • 2
    What have you tried? The jQuery `.html()` or `.text()` functions seem applicable here. I see no attempt. – David Aug 29 '17 at 20:28
  • Possible duplicate of [How to append data to div using JavaScript?](https://stackoverflow.com/questions/5677799/how-to-append-data-to-div-using-javascript) – Surreal Aug 29 '17 at 20:34
  • In both cases I'm new to jQuery I just want to know what is the next step after this one,, how to connect this code to my html tags to execute it and get the output, and my be may attempts r stupide to post, that's why better not to post them. – Dreamer64 Aug 29 '17 at 20:53
  • Try $('div').text(thisUserAccount.Title); – iSZ Aug 29 '17 at 22:03
  • I did but its not working – Dreamer64 Aug 30 '17 at 14:46

1 Answers1

0

Add this to your script:

var div = document.getElementById('divID');
div.innerHTML += thisUserAccount;
Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
DCR
  • 14,737
  • 12
  • 52
  • 115
  • do a console.log(thisUserAccount) and see if you have anything there – DCR Aug 30 '17 at 14:57
  • Not working too, I believe that the script is not working anymore because a static text like this document.getElementById("1").innerHTML = ('test'); is working however its not working with that variable in the script! – Dreamer64 Aug 30 '17 at 15:52
  • I think your problem is with: var thisUserAccount = $().SPServices.SPGetCurrentUser({ fieldName: "Title", debug: false – DCR Aug 30 '17 at 19:28