Ok so finding any material on this
or $(this)
using any search engine is ridiculously hard. So I hope I haven't missed something obvious.
Basically what I'm trying to accomplish parsing of a click'd DOM object into a function and then operating recursively through that object's siblings and running some operators. (you can find the code below along with a link to the live page)
All the reference's I've found thus far (including this) have involved calling built-in function on $(this)
such that $(this).find('p')
however what I'm trying to do is parse it as a parameter to my function thus insertRow($(this))
is this possible? If not how can I use the above call style and access the object in my function?
Here's the code I've got thus far. I've included addRow
to show what I've got working currently. And the works in progress are insertRow(row)
and incrementRows(row)
. I guess it's also possible that I've screwed up the layering of .click
events in the `$(document).ready(); area. I'm really at a loss currently.
Oh and the page as it stands. http://azarel-howard.me/stage-management/script-writer/
var currentScene = 1, currentRow = 0;
function addRow() {
if (currentRow==0) {
$("#scriptContent").append("<div class=\'row\' data-scene=\'" + currentScene + "\' data-row=\'" + currentRow + "\'><div class=\'col-lg-2\' id=\'scene\'><div class=\'row\'><div class=\'col-lg-12\'><label class=\'checkbox checked\' for=\'checkbox1\'><span class=\'icons\'><span class=\'first-icon fui-checkbox-unchecked\'></span><span class=\'second-icon fui-checkbox-checked\'></span></span><input type=\'checkbox\' value=\'\' id=\'checkbox1\' data-toggle=\'checkbox\'>New Scene</label></div></div><div class=\'row\'><div class=\'col-lg-12\'><h6>Scene " + currentScene + "</h6></div></div></div><div class=\'col-lg-10\' id=\'script;\'><textarea rows=\'3\' placeholder=\'Add Scene Title...\' class=\'form-control\'></textarea></div></div> <!-- row close -->");
currentRow++;
} else {
$("#scriptContent").append("<div class=\'row\' data-scene=\'" + currentScene + "\' data-row=\'" + currentRow + "\'><div class=\'col-lg-2\' id=\'scene\'><div class=\'row\'><div class=\'col-lg-12\'><label class=\'checkbox\' for=\'checkbox1\'><span class=\'icons\'><span class=\'first-icon fui-checkbox-unchecked\'></span><span class=\'second-icon fui-checkbox-checked\'></span></span><input type=\'checkbox\' value=\'\' id=\'checkbox1\' data-toggle=\'checkbox\'>New Scene</label></div></div><div class=\'row\'><div class=\'col-lg-12\'><input type=\'text\' placeholder=\'Line Label\' class=\'form-control input-sm\'></input></div></div></div><div class=\'col-lg-10\' id=\'script;\'><textarea rows=\'3\' placeholder=\'Add script...\' class=\'form-control\'></textarea></div></div> <!-- row close -->");
currentRow++;
}
}
function insertRow(row) {
incrementRows(row.next().find(".row"));
$(row).after("<div class=\'row\'><div class=\'col-lg-2\' id=\'scene\'><div class=\'row\'><div class=\'col-lg-12\'><label class=\'checkbox\' for=\'checkbox1\'><input type=\'checkbox\' value=\'\' id=\'checkbox1\' data-toggle=\'checkbox\'>New Scene</label></div></div><div class=\'row\'><div class=\'col-lg-12\'><input type=\'text\' placeholder=\'Line Label\' class=\'form-control input-sm\'></input></div></div></div><div class=\'col-lg-10\' id=\'script;\'><textarea rows=\'3\' placeholder=\'Add script...\' class=\'form-control\'></textarea></div></div> <!-- row close -->");
}
function incrementRows(row) {
var nextRow = $(row).next().find(".row");
if (row.data("scene") == nextRow.data("scene")) {
if ((row.data("row")+1) == nextRow.data("row")) {
incrementRows(nextRow);
}
}
row.data("row") += 1;
}
$(document).ready(function(){
$("#addRowBtn").click(addRow);
$("#insertRowBtn").click(function() {
// solution applied
//$(".row").click(insertRow(this));
$(".row").click( function() {
insertRow($(this))
});
});
//$(".checkbox").click(function() {
// if ()
//})
addRow();
addRow();
});