3

Page: http://csgo.exchange/

I am trying to simulate a click on the "Item Float" option from the "Calculator" menu via jQuery but it's not loading the desired window.

My code:

var itemfloat = $('li').find('a[href$="#item/market"]');
itemfloat.click();

What's ridiculous is that itemfloat.remove(); works but not itemfloat.click();

IMPORTANT: The scripts runs as intended when pasted in the console but not when run as a content script in a Chrome Extension..

user3745387
  • 165
  • 1
  • 7
  • 1
    It does work for me...Paste these lines in console and test.. – Rayon Mar 30 '16 at 10:34
  • True! It does! I'm surprised. I'm running the script through a Chrome Extension content script and it's not working. – user3745387 Mar 30 '16 at 10:38
  • is `jQ` included ? – Rayon Mar 30 '16 at 10:39
  • Yes, it's loaded as a content script. – user3745387 Mar 30 '16 at 10:49
  • Dont provide additional information in comments; always edit/update your question instead. Not everybody will take the time to dive through all the comments; so that limits your chance of getting good answers. – GhostCat Mar 30 '16 at 11:08
  • Try adding `eq()` at the end of selector. I mean like this `$('li').find('a[href$="#item/market"]').eq(0)` – rmondesilva Mar 30 '16 at 11:33
  • Possible duplicate of [Triggering a click event from content script - chrome extension](http://stackoverflow.com/questions/17819344/triggering-a-click-event-from-content-script-chrome-extension) – rsanchez Mar 30 '16 at 11:57

2 Answers2

0

it work, but you can simplify it for better code reading

$('li').find('a[href$="#item/market"]').click();
Thomas Bormans
  • 5,156
  • 6
  • 34
  • 51
Radu Lozovanu
  • 167
  • 4
  • 17
  • What is `$('li').find('a[href$="#item/market"]')` is used many times in the code ? – Rayon Mar 30 '16 at 10:42
  • True, but for a single time use, is better and more clearly, easy to understand the code for the next developer that comes. – Radu Lozovanu Mar 30 '16 at 10:46
  • @RaduLozovanu, for `triggering` others DOM `click`, refer this [demo](https://jsfiddle.net/shashank2691/zeuenokm/). – Shashank Mar 30 '16 at 11:25
0

I found the answer I needed at:Triggering a click event from content script - chrome extension

Working code:

$('li').find('a[href$="#item/market"]')[0].click();
Community
  • 1
  • 1
user3745387
  • 165
  • 1
  • 7