Javascript onClick using member function?

Up vote 0 down vote favorite share g+ share fb share tw.

I've got a function here which is intended to deleted a chunk of HTML related to a specific object. This happens when a minus ('-') sign on the page is clicked. So, my object has a delete button as part of it's html structure.

When clicked (onClick) it should remove the child Element(itself) and it's removed from a linked list I have intended to keep track of everything's relative place. SO, here's what we have: // We're making an instruction list, so this is // a "step" in the instructions, which we encapsulate in // an object. Parent_container is a div that we're // attaching this good stuff too.

Function step() { // // initializations, which are set outside the constructor, but before the delete // button can be clicked this. Next = null; this. Prev = null; this.

Identifier = unique; // ... making all the divs and html stuctures ... this. Container = document. CreateElement('div'); this.container.id = step_container_id+current_count; // the delete button's all set up, now we need to define it's callback!

Delete_button. Onclick = this. Delete_step; // and hook that bad mama jama into the rest of the DOM this.container.

AppendChild(delete_button); // last little hook ups step_container. AppendChild(step_title); // etc... } // Here's how I make it a member: step.prototype. Delete_step = function() { // and here's me seeing if things worked out: alert(this.container.id) } What we end up getting is a crash because container is undefined.

"this" is not an object either. Ultimately, I need to create a way to have onClick result in me having access to a specific objects attributes, relative to which object was clicked. If I can do that, we're golden.

Cheers! EDIT: I feel I may have created confusion with step.prototype. Delete_button = function(), that was a typo.

It's name is delete_step. Delete_button is just a tag. So we're trying to get at the step objects container variable using a method called delete_step() which is called when the delete_button tag is clicked.

Sorry! Javascript events dom onclick link|improve this question edited Aug 15 '11 at 17:34 asked Aug 15 '11 at 16:37PandemoniumSyndicate1017 79% accept rate.

Use var step = function ... – Senad Meškin Aug 15 '11 at 16:40 I think you may be suffering some confusion over member scope/availability - read this. This should always be an object (although to be fair everything in Javascript is an object apart from undefined and null) but it isn't always what you think it should be inside inner functions. Read the link above.

And everything else ever written by Douglas Crockford. – DaveRandom Aug 15 '11 at 16:46.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions