Select Categories Below
Advertisement
Start Your Own Q&A Site
Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.
Status: Closed Points: 75 Time: 11:37 - Nov 26, 2006
jgivoni
I am a bit confused by this - I have been trying to add a method that will return true or false whether an element (retrieved with document.getElementById("example")) has a specified class name assigned. I have tried with the "prototype" method and without - I have used "= new Function(string)" and "= function(){}" syntax and sometimes it works in one browser, sometimes in another, but I can't figure out why or why not. Please shed some light on this for me; this is what I want to do: x = document.getElementById("example"); if (x.hasClassName("test")) { <something> } (and I am not interested in an alternative way to do it...)
Categories:
Add Categories
When adding more than one category, separate them with commas.
xarcus
Date:: Nov 28, 2006
Time:: 12:40
With Firefox / Mozilla it works as expected HTMLElement.prototype.hasClassName = function( test){ return this.className == test} With MSIE 6.0 document.getElementById( "myID").property shows "undefined" MSoft does not follow standards. There is also a compile switch that affects prototype: ( See Note at http://msdn2.microsoft.com/en-US/library...) >> The prototype property of a built-in object cannot be modified when running in fast mode, the default for JScript. To compile a program from the command line that uses the prototype property, you must turn off the fast option by using /fast-. It is not safe to turn off the fast option in ASP.NET because of threading issues.
Time:: 12:44
I am sorry! fortget previous msg. I wrote property instead of prototype at With MSIE 6.0 document.getElementById( "myID").pro... With Firefox / Mozilla it works as expected HTMLElement.prototype.hasClassName = function( test){ return this.className == test} With MSIE 6.0 document.getElementById( "myID").prototype shows "undefined" MSoft does not follow standards. There is also a compile switch that affects prototype: ( See Note at http://msdn2.microsoft.com/en-US/library.......) >> The prototype property of a built-in object cannot be modified when running in fast mode, the default for JScript. To compile a program from the command line that uses the prototype property, you must turn off the fast option by using /fast-. It is not safe to turn off the fast option in ASP.NET because of threading issues.
Time:: 12:59
Check this link too: http://www.codeproject.com/jscript/cross... at the paragraph "Prototypes with HTML objects"
Time:: 13:27
So you may add methods to HTL objects only in non MSIE browsers if (isGecko) { // add the method HTMLElement.prototype.hasClassName = function( test){ return this.className == test} } else if (isMSIE) { // add the function var hasClassName = function( elem, test){ return elem.className == test} }
Date:: Jan 09, 2007
Time:: 15:01
Ok, xarcus, thanks for that. What I understand now is that IE doesn't 'expose' the html-element object so that it is impossible to 'prototype' it. I've tried some of the scripts that are supposed to define the 'missing' HTMLElement in IE and copy all the properties from the 'unidentified' object but for some reason I didn't get it to work. Everything works wonderfully well in most other browsers though. Jakob
Question Answered
This question has been closed, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Questions
whats the best food to eat during midnight?
How to identify the tiffany jewelry? www.tffanycheapmall.com.
Send an email alert to each user of the php application based on criteria
How I Increased My AdSense Earnings?
how to choose the lady dress ?
How can I fulfill the minimum requirement to make your computer support 3D?
You have 100 characters to use
Rank
Expert
Points
1.
10354
2.
6493
3.
5596
4.
4848
5.
3487
6.
2840
7.
2770
8.
2303
9.
1820
10.
917
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software