I have two functions in a data tool that I'm making - showEditDv(object) and editDv(object). If you haven't already guessed, Dv stands for Data Value. showEditDv is called when you click on the edit data icon. It generates an Opentip tooltip that (will) allow you to edit data, and is called like this: showEditDv(this); in an onclick attribute. Here is the code for that function (no, there aren't inline comments in the actual thing):
function showEditDv(object) {
var name = $(object).attr("data-name"); // string(name) now holds the name of the data value
var input = new Opentip($(object), {target: null, showOn: null, hideTrigger: "closeButton"});
input.setContent("<label>Name:</label><input type='text' value='" + name + "' class='dv-add-name' /><label>Value:</label>input type='text' class='dv-add-value' value='" + data[name] + "' /><button onclick='editDv(" + $(object) /*<-- problem */ + ");'>Apply</button>");
input.show();
}
The problem arises when the editDv() function is called by the 'Apply' button. Because the object is being referred to in a string (I think!), the object reference is printed as [object Object], and the function cannot hide the Opentip because it doesn't have a reference for it. Here is the code for editDv():
function editDv(object) {
var input = $(object).data("opentips")[0]; // data("opentips") is an array of objects
input.hide();
}
So my question is: how can I pass the input object from showEditDv to editDv as an argument, or is there a better way to do this entirely?
<button>-var button = $("<button>"), set itsclickevent to do exactly what you need -button.on("click", function () { /* do whatever */ });and use.append()where you need to add it somewhere.idof the element, instead of the element itself (which isn't possible in your situation, as you've found out), and then get the element by using theidthat was just passed. It's a little easier, but not proper