Answer the question
In order to leave comments, you need to log in
How to make a click on an element that can appear and disappear depending on clicking on different elements on the site?
I want to make a small extension for vk.com, but I started having problems almost immediately. There, many elements are created dynamically and I don’t know how to hang a handler on them.
manifest.json
{
"content_scripts": [ {
"css": [ "style.css" ],
"js": [ "jquery-3.3.1.min.js", "content.js" ],
"matches": [ "*://vk.com/*", "*://*.vk.com/*" ],
"run_at": "document_end"
} ],
"icons": {
"128": "icons/128x128.png",
"16": "icons/16x16.png",
"19": "icons/19x19.png",
"38": "icons/38x38.png",
"48": "icons/48x48.png"
},
"manifest_version": 2,
"version": "1.0.1",
"web_accessible_resources": [ "*.js" ]
}
$(function ($) {
if( location.host == "vk.com" ) {
// $("body").on("click", "...", function( e ) { alert('123'); }); - не работает, не цепляется событие
$('...').click(function() { alert('123'); }); // работает, только если элемент на странице уже существует
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question