最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Chrome Developer Tools Issue with Jquery in the Console - Stack Overflow

programmeradmin3浏览0评论

When I try to execute below JQuery code in Google Chrome's developer tools

$("#u_16_0").val("AJ College, Sivakasi")

am getting below error:

Uncaught Error: <[EX[["Tried to get element with id of \"%s\" but it is not present on the page.","#u_16_0"]]]>(…)h @ LGuPoDEwQGD.js:36i @ LGuPoDEwQGD.js:36(anonymous function) @ VM580:1

Could somebody please help me to resolve this issue? I've verified that the element is present in the page. I mean if I just type $("#u_16_0") in the console, the element is printed.

Please see the below link to screenshot containing version information of my Google Chrome.

[

UPDATE - 1

I managed to accomplish this with the below plain javascript code

document.getElementById("u_16_0").value="University of Cambridge"

UPDATE - 2

Amin's answer based on jQuery also worked. Hence, accepted it as answer and awarded bounty.

When I try to execute below JQuery code in Google Chrome's developer tools

$("#u_16_0").val("AJ College, Sivakasi")

am getting below error:

Uncaught Error: <[EX[["Tried to get element with id of \"%s\" but it is not present on the page.","#u_16_0"]]]>(…)h @ LGuPoDEwQGD.js:36i @ LGuPoDEwQGD.js:36(anonymous function) @ VM580:1

Could somebody please help me to resolve this issue? I've verified that the element is present in the page. I mean if I just type $("#u_16_0") in the console, the element is printed.

Please see the below link to screenshot containing version information of my Google Chrome.

[

UPDATE - 1

I managed to accomplish this with the below plain javascript code

document.getElementById("u_16_0").value="University of Cambridge"

UPDATE - 2

Amin's answer based on jQuery also worked. Hence, accepted it as answer and awarded bounty.

Share Improve this question edited Dec 8, 2016 at 10:12 asked Nov 19, 2016 at 16:26 user6077173user6077173 8
  • What kind of element is #u_16_0 in this context? – roberrrt-s Commented Dec 1, 2016 at 10:15
  • Can you post the html of the element? – Aruna Commented Dec 1, 2016 at 10:16
  • It is <input type="text"/> – user6077173 Commented Dec 1, 2016 at 10:19
  • Can you post the actual markup, you can right click on the element on th page and click inspect element, it will show the mark up the element. Then right click on the mark up and then copy and then click copy outer html. Can you post the same here? – Aruna Commented Dec 1, 2016 at 10:22
  • 2 Are you on Facebook where $ is not jQuery. $("contentCol") – epascarello Commented Dec 2, 2016 at 5:25
 |  Show 3 more comments

4 Answers 4

Reset to default 7

Note: Do not expect $ is always JQuery.

The Chrome console does not appear to have access to the content script's execution context.

Wrong, it does. You need to look at the correct place:

Instead of <page context> below in the animation, you have to select chrome-extension://<your extension id>

You can click "top" below in your version of chrome.

The previous screencast shows that the Console tab of the Chrome developer tools has two dropdown boxes at the bottom, which can be used to change the execution environment for the developer tools' console.
The left side can be used to change the frame context (top frame, so iframe, ...), and the right side can be used to change the script context (page, content script, ...).

Reference: Why will jQuery not load in Facebook?

The problem is when you assume that $ is always jQuery and it is not. Simple way to see if it is to console.log($) and see what it returns.

jQuery usually returns

function (selector,context){return new jQuery.fn.init(selector,context)}

or

function (a,b){return new n.fn.init(a,b)}

Now anyone can define $ to be anything. On Facebook it appears to be an alias for document.getElementById() and has some checks in it

function i(j){return h(j);}

running $("contentCol") will return a DOM element.

And if $ is not defined, in Chrome Dev tools, it is an alias for document.querySelector

$(selector, [startNode]) { [Command Line API] }

so in the end, do not expect $ to be jQuery.

This is because of jQuery $ sign conflict with other libraries like some facebook js libraries. you should use jQuery instead of $:

jQuery("#u_16_0").val("AJ College, Sivakasi");

From looking at this answer it looks as though your call to:

$("#u_16_0")

is not actually calling jQuery.

Try changing the page context

发布评论

评论列表(0)

  1. 暂无评论