php - I'm trying to change the value of a div with javascript -


<div id='right_side'> <div id='t' title='<?php echo $u; ?> friends'>     <div id="f">         <h6>             <?php echo $u; ?> friends         </h6>     </div> </div> <div id='users' onclick="chat();">     <?php echo $friend; ?>  </div> 

javascript

<script>  function chat() {      var chatbox = document.getelementbyid("chatbox");      var chatbox = document.getelementbyid("chatbox").value= "<?php echo $friend_username; ?>";      if(chatbox.style.display == "none"){          chatbox.style.display = "block";          $('#chatbox').attr("chatbox","<?php echo $friend_username; ?>");      } else {          chatbox.style.display = "none"; chatbox.attr.value = "none";      } }  </script> 

i want change div value user name of friend if click name.

i want change div value user name of friend if click name.

use button (not div) monitor presses, , include username in data attribute:

<button type="button" data-user="bob" class="add-user">bob</button> 

then jquery can this:

$(document).on('click', '.add-user', function(){   // username data attribute   var usr = $(this).data('user');   // update div's html   $('#chatbox').html(usr); }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -