0

I have a little problem with my Chrome extension. My manifest.json:

    [..]
"background": {
    "page": "background.html",
    "persistent": false
  },

  "content_scripts": [
    {
      "matches": ["http://*/", "https://*/"],
      "js": [
        "js/jquery-3.2.1.js"
      ]
    }
  ],

"permissions": [
"unlimitedStorage",
"tabs",
  "activeTab",
  "browsingData",
"notifications",
"webNavigation",
"http://*/",
"https://*/"
]

And in one of the JavaScript file I have something like that:

        chrome.tabs.executeScript( tabId, {
            code:"$('#user').attr('value','test');"
            });

Why doesn't it work? When I'll replace this with:

        chrome.tabs.executeScript( tabId, {
            code:"document.getElementById('user').value='test';"
        });

Everything is OK. Why this jQuery doesn't work?

Makyen
  • 31,849
  • 12
  • 86
  • 121
  • 2
    Because `value` is not an attribute. Use `.prop('value', 'test')`, see also [.prop() vs .attr()](//stackoverflow.com/q/5874652) – wOxxOm Jul 06 '17 at 20:09
  • ahh my mistake, works, thanks :) – marcin7848 Jul 06 '17 at 20:44
  • HTML Elements have attributes. See: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. But each element is in effect a JavaScript object. For Example HTMLDivElement. Javascript objects have properties. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors. Hence you are adding a property to a Element called value with the contents test in the latter example. – JGFMK Jul 07 '17 at 12:10

0 Answers0