$('ul#test a').click(function(){
$('this').closest('parent').find('textarea').val(this.getAttribute('href'));
});
works in Google Chrome
snippet but not loaded with Tampermonkey
.
I think that it's trying to set a value before even finding the target
(edit) whole script :
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match www.reddit.com/r/some-subreddit
// @grant none
// ==/UserScript==
(function() {
'use strict';
$( "textarea" ).one("click",(function() {
$(".usertext-edit").prepend ( `
<div id="gmSomeID"><ul id="gmSomeeID"><a href="#stickers1"</a> <a href="#stickers2"</a> <a href="#stickers3"</a> <a href="#stickers4"</a> <a href="#stickers5"</a ><a href="#stickers6"</a> <a href="#stickers7"</a> <a href="#stickers1"</a> <a href="#stickers2"</a> <a href="#stickers3"</a> <a href="#stickers4"</a> <a href="#stickers5"</a> <a href="#stickers6"</a>
</ul></div>
` );
$('ul#gmSomeeID').css({
'overflow-y':'scroll',
'display':'block',
'overflow-wrap' : 'normal',
'height':'100px',
'background-color':'white'
});
$('ul#gmSomeeID a').click(function(){
$("this").closest("div.usertext-edit")
.find("textarea")
.val($("this")
.closest("div.usertext-edit")
.find("textarea")
.val() +' '+ '[](' + this.getAttribute('href') + ') ');
});
}));
})();
It displays some pictures above textarea's and I'm trying to make it insert them in the said textarea when they're clicked on