Hopefully someone can help me with this code I have.
JavaScript:
function myFrame(id){
if (id) {
if (window === this) {
return new myFrame(id);
}
this.e = document.getElementById(id);
return this;
} else {
return "";
}
}
myFrame.prototype = {
math: function () {
alert(1 + 1);
},
hide: function () {
this.e.style.display = 'none';
return this;
}
}
HTML:
<p id="hideParagraph">Hide Paragraph</p>
<input type="button" name="math" onclick="hide()" value="Hide Paragraph" />
<input type="button" name="math" onclick="math()" value="Alert Math" />
<script type="text/javascript">
function math() {
myFrame("body").math();
}
function hide() {
myFrame("hideParagraph").hide();
}
</script>
The code above works fine but I want to know is there a way not to specify an element.
For example I need to specify "body" or some other string value in order for this code to work, else I get a "is not a function" error message
myFrame("body").math();
Is there a way for me to have this code like :
myFrame().math();
And also still use the "hide" method like:
myFrame("hideParagraph").hide();
Any help is much appreciated!
The problem is your
Try: