I'm trying to append a transparent layer to some elements with an edit button within. The edit button has an onclick function. The value transfered with the onclick is an ID from the parent element (whom the transparent layer is appended upon)
My problem is, that all the edit buttons unfortunately carry the same value: cms-block-3.
What am I doing wrong?
I hope I explained myself properly. Thanks in advance!
Example of HTML:
<div class="editable cms-block-1">Some</div>
<div class="editable cms-block-2">Someting else!</div>
<div class="editable cms-block-3">Something else else! :)</div>
$(document).ready(function() {
$('.editable').each(function(index) {
$($(this).attr('class').split(' ')).each(function() {
if (this !== '' && this.substring(0, 3) == "cms") {
element = this.toString();
}
});
var $t = $(this);
var offset = $t.offset();
var dim = {
left: offset.left,
top: offset.top,
width: $t.outerWidth(),
height: $t.outerHeight()
};
$('<div class="editable-focus"></div>').css({
position: 'absolute',
left: dim.left + 'px',
top: dim.top + 'px',
width: dim.width + 'px',
height: dim.height + 'px'
}).appendTo(document.body).append('<input type="button" value="Edit" class="edit-btn" onclick="edit_area(element)" />');
});
});
$($(this).attr('class').split(' '))This seems crazy...