Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner Web Resource

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

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

Thank you. It helps me a lot

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across Jira Cloud instance.   📢 Get y...

238 views 11 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you