javascript - Jquery Help - OnClick send Title to Clipboard -


i new javascript/jquery.

i have below lines part of table dynamically creating db query. end goal jquery function when span clicked send contents of title attribute of span clipboard, far can't seem find value, getting undefined when click on of span/columns.

<tr>     <td id="1avifilepath"><span style='color:red;' onclick='copytoclipboard()' title='c:/ftp/dasales/working/file/event/1e03029b20160107101053001i100.avi' >false</span></td>     <td id="1avisuccess"><span style='color:red;' onclick='copytoclipboard()' title='c:/tos3/1e03029b20160107101053001i100.mp4'>false</span></td>     <td id="1avicopy"><span style='color:red;' onclick='copytoclipboard()' title='e:/originalavis/1e03029b20160107101053001i100.avi'>false</span></td>     <td id="1avifail"><span style='color:red;' onclick='copytoclipboard()' title='f:/avifailed/1e03029b20160107101053001i100.avi'>false</span></td>     <td id="1avis3loc"><span style='color:red;' onclick='copytoclipboard()' title='s3://pathto/file/1e03029b20160107101053001i100.avi'>false</span></td>     <td id="1mp4s3loc"><span style='color:red;' onclick='copytoclipboard()' title='s3://pathto/file/1e03029b20160107101053001i100.mp4'>false</span></td> <tr>  <script>     function copytoclipboard() {         var str = $(this).attr('title');         console.log(str);     } </script 

you need remove onclick attribute span tags , set event listener shown below. note: need selector jquery on method added class name (here called "clickable", anything) table row element.

more information jquery on method can found here:

http://api.jquery.com/on/

function copytoclipboard() {      var str = $(this).attr('title');      console.log(str);  }    $(document).ready(function () {      $('.clickable').on('click', 'span', copytoclipboard);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table>      <tr class="clickable">          <td id="1avifilepath"><span style='color:red;' title='c:/ftp/dasales/working/file/event/1e03029b20160107101053001i100.avi' >false</span></td>          <td id="1avisuccess"><span style='color:red;' title='c:/tos3/1e03029b20160107101053001i100.mp4'>false</span></td>          <td id="1avicopy"><span style='color:red;' title='e:/originalavis/1e03029b20160107101053001i100.avi'>false</span></td>          <td id="1avifail"><span style='color:red;' title='f:/avifailed/1e03029b20160107101053001i100.avi'>false</span></td>          <td id="1avis3loc"><span style='color:red;' title='s3://pathto/file/1e03029b20160107101053001i100.avi'>false</span></td>          <td id="1mp4s3loc"><span style='color:red;' title='s3://pathto/file/1e03029b20160107101053001i100.mp4'>false</span></td>      <tr>  </table>


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 -