M
M
maksam072018-04-02 20:00:00
Google Chrome
maksam07, 2018-04-02 20:00:00

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" ]
}

jquery-3.3.1.min.js - respectively jquery
content.js library
$(function ($) {
  if( location.host == "vk.com" ) {
    // $("body").on("click", "...", function( e ) { alert('123'); }); - не работает, не цепляется событие
    $('...').click(function() { alert('123'); }); // работает, только если элемент на странице уже существует
  }
});

I've been suffering for several hours now, has anyone experienced this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question