How to access css selector from chrome inspector

952 views
Skip to first unread message

absolutelyf...@gmail.com

unread,
Jun 13, 2013, 6:58:10 PM6/13/13
to google-chrome-...@googlegroups.com


Is there a way to copy the text of the selected element in google chrome inspector? I want to use the reference in a css stylesheet. 

The string 'div#PageList1.widget.PageList'  is also available as title when hovering over the element in the bottom bar.


Any ideas how to get this string?

Timothée Boucher

unread,
Jun 13, 2013, 8:54:53 PM6/13/13
to google-chrome-...@googlegroups.com, absolutelyf...@gmail.com
In the console, $0 is the last selected element.
So you can get the list of classes with $0.className (or you can also check out classList).

From that and tagName, you should be able to build what you want. (you might want to look at snippets for that: https://developers.google.com/chrome-developer-tools/docs/authoring-development-workflow#snippets)

Unless I'm misunderstanding what you're trying to do, which is totally possible :)

Hope that helps,

Tim

PhistucK

unread,
Jun 14, 2013, 3:55:38 AM6/14/13
to Timothée Boucher, Google Chrome Developer Tools, absolutelyf...@gmail.com
Yes, something like -
copy($0.nodeName + ($0.id? "#" + $0.id: "") + ($0.className.replace(/^[\s\t]+|[\s\t]+$/)"." + $0.className.replace(/^[\s\t]+|[\s\t]+$/).split(" ").join("."): ""));

But it is a bit cumbersome as opposed to right clicking or selecting the text and copying.


PhistucK


--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Timothée Boucher

unread,
Jun 14, 2013, 12:10:52 PM6/14/13
to google-chrome-...@googlegroups.com, absolutelyf...@gmail.com
I thought maybe an extension that adds a contextual menu to do that would work, but as PhistucK said in that post (https://groups.google.com/forum/#!msg/google-chrome-developer-tools/5rWuaXMfjwQ/l_LaGq4PGnsJ), you can't add contextual menu in a devtools panel.

That being said, it might be possible to have a panel that will do that "math" and paste it to the clipboard whenever opened. Sledgehammer, meet fly. :) 


PhistucK


To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-developer-tools+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages