Reputation: 55
How to do onclick and href both in anchor tag, in javascript. my code is :
enter code here
for (l = 0; l < k; l++) {
var tmp1 = searched_headings_filename[l];
var tmp2 = searched_headings[l];
frameDoc.body.innerHTML += '<div style="margin-left:10;"><li class="highlight"><a onclick="highlightSearch();" href="' + tmp1 + '">' + searched_headings[l] + '</a></li></div>';
}
Please help me...
Upvotes: 0
Views: 376
Reputation: 400
I suppose you want to run some js function on click, and then redirect to whatever is in the href? Try this
<a href="javascript:YourFunctionName(someParameter);">displayName</a>
Then in js function
function YouFunctionName(someParameter){
// do your logic
window.location = 'someUrlYouWantToRedirectTo';
};
Upvotes: 1