get sender obj by event

Costas

Administrator
Staff member
reference
http://javascript.info/tutorial/obtaining-event-object

The event object is always passed to the handler and contains a lot of useful information what has happened.


various line will be something like :
onclick='javascript:test("999",event)'

the event object doesnt exist in my code structure, browsers which follow W3C standards always pass the event object!

JavaScript:
<script>
.
.
.

	function fill_list(db)
		for (var i = 0; i < db.length; i++)
		{
			rows += "[TR][TD][/TD][TD]" + db[i]["offer_id"] + "[/TD][TD]" +
			"<a id='" + db[i]["offer_id"] + "' onclick='test(" + db[i]["offer_id"] + ",event)' class='btn btn-danger btn-xs']Mark as Paid</a>[/TD][/TR]";
		}
		
		$("#table").html(rows);
	}
 
	function test(offer_id,eventt){
		console.log(eventt);
		var t = eventt.srcElement;
		console.log(t);
		
		//get ID by sender!
		$("#"+t.id).hide();
	}

</script>
[/javascript]

at first 
[img]https://www.pipiscrew.com/wp-content/uploads/2014/12/snap331.png[/img]

at second (when user clicked the red button)
[img]https://www.pipiscrew.com/wp-content/uploads/2014/12/snap331b.png[/img]

[img]https://www.pipiscrew.com/wp-content/uploads/2014/12/snap333.png[/img]
1-console.log(eventt)
2-console.log(eventt.srcElement)
 
Top