Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

1 vote
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
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

Darin Hafer August 22, 2024

Hello, where do you put the javascript? Is that stored in a scriptrunner web resource?

Suggest an answer

Log in or Sign up to answer