javascript - jQuery .click(handler) finds input element blank in Greasemonkey script (addEventListener works, however) -
i have greasemonkey script associating between jira , ticket app. when associate item jira ticket, makes api posts jira add other ticket jira it's bidirectional. relavant html (which don't have control change) is:
<div id="related_inputs" class="related-items-actions-inner"> <label class="align" style="width: 104px;">full_jira_url: </label> <input type="text" style="margin-left: 109px;"> <br> </div>
and button:
<a id="relate-button" class="tt_button"> <span id="relate-button-text">relate</span> </a>
so when user clicks button/link, want extract value input in input above (in "related inputs" div) , other stuff. used work , not longer i'm not sure if due browser regression, jira change or change website code i'm writing script for.
the gist of greasemonkey script is:
(function () { console.log("started script!"); $('#relate-button').click( function(event) { var related_ticket_type = $('#related_inputs label').text().trim(); console.log("ticket type " + related_ticket_type); if (related_ticket_type != jira_label_text) { return; } var jira_url = $('#related_inputs input').val(); console.log(jira_url); // <<== "" time when input has data in when pressed var match = jira_url.match(jira_regex); if (match.length != 2) { console.log("we didn't match url valid rds jira url.") return; } ...
the issue value i'm getting input element empty everytime. i've confirmed in console correct input element. label element correct 2 since getting input code.
any ideas or suggestions?
after discovered below, question comes down to: difference between jquery's .click(handler) vs element.addeventlistener( 'click', function(event) {...}, true) ?
so instead of using jquery's .click(handler), did following:
var button_el = document.getelementbyid('relate-button'); button_el.addeventlistener( 'click', function(event) {....}, true);
doing fixed issue (ie value of url not blank). however, i'd interested in knowing why fixed issue.
i'm using greasemonkey 1.15.
Comments
Post a Comment