ScriptRunner Web Resource

wangzehong June 2, 2021

I added a button(web item) to the search question page, but I couldn't do it by injecting JS binding buttons

This is a screenshot of the item I added

image.png

 

this is my js script

$("key1").on("click",function(){
alert('call me');
});

 

When I click that button, it just refreshes the page. Can anyone help me, thank you

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2021

Try putting this in your javascript instead:

AJS.$(document).ready(function () {
AJS.$("#key1").on("click",function(e){
e.preventDefault();
alert('call me');
});
});

A few things going on,

1) makes sure to bing the event only after the page is done loading (to be sure the web item is available

2) In jira, the Jquery is called with AJS.$

3) To get the item you created with key=key1, you need an "id" selector, so start it with #

4) User preventDefault() to stop the default action on the <a> tag that you are clicking

wangzehong June 24, 2021

Thank you. It helps me a lot

Suggest an answer

Log in or Sign up to answer