Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create onclick for a link

i have a div for which i set value dynamically during run time, if there is value than i have enable or create a link which will have onclick method where i will call a javascript method.

how to do this in jquery or javascript?

I set value to a div like the following,

document.getElementById('attachmentName').innerHTML=projectInforamtionMap.Cim_AttachmentNames;

this the div :

<tr>
  <td align="left"><div id="attachmentName"> </div></td>
</tr>

Kindly help me to find and fix.

Best Regards

like image 552
Java Questions Avatar asked Feb 21 '13 11:02

Java Questions


2 Answers

You can set a onclick function:

document.getElementById('attachmentName').onclick = function() {};
like image 103
Jefferson Henrique C. Soares Avatar answered Oct 16 '22 18:10

Jefferson Henrique C. Soares


Assume that your function are previously define like this

function foo(){alert('function call');}

After adding innerHTML

In Javascript

document.getElementById('attachmentName').setAttribute('onclick','foo()');

In Jquery

$("#attachmentName").attr('onclick','foo()');
like image 32
Dineshkani Avatar answered Oct 16 '22 18:10

Dineshkani