Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2012, 12:50 PM   PM User | #1
u jayakodi
New Coder

 
Join Date: Sep 2010
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
u jayakodi is an unknown quantity at this point
Display Element Details

This snippet shows the details like Tagname, type, ID, Style and Global style, when the mouse is moved over any element of a page, which need to be traced otherwise only in the source file.

The code can be added in a script block or saved as a js file and referred in the head section. A model html file in whatisit.zip demonstrates the use.

jayakodiu@yahoo.com

Code:
document.onmousemove=function(){var ele=event.srcElement;tt=ele.tagName;if(tt=="BODY"){return}
if(tt=="INPUT"){tt+="\ntype = "+ele.type}
tid=ele.id;if(tid!=""){tt+="\nid = "+tid}
tcs=ele.style.cssText;if(tcs!=""){tt+="\nStyle:"+"\n"+ele.style.cssText}
zt="";if(document.styleSheets.length>0){sn=document.styleSheets(0).rules.length;zt=""
for(i=0;i<sn;i++){dn=document.styleSheets[0].rules[i].selectorText
if(ele.tagName==dn){zt="\nGlobal style  Defn:\n"+document.styleSheets[0].rules[i].style.cssText}}}
ele.title=tt+zt}
Attached Files
File Type: zip Whatisit.zip (858 Bytes, 38 views)

Last edited by VIPStephan; 11-08-2012 at 10:38 PM.. Reason: fixed code BB tags
u jayakodi is offline   Reply With Quote
Old 11-08-2012, 08:13 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
1. It would work just as well if attached to the regular spot for JavaScript of just before the </body> tag.

2. If you wrap the code in an anonymous function then it would ensure it doesn't clash with any other script in the page apart from any using document.onmousemove (to avoid that clash you could substitute an event listener).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:47 PM.


Advertisement
Log in to turn off these ads.