2
I’m trying to add tags to a photo (like the facebook identification system), the error I’m having is this:
When I click on an image to put the tags the form first appears in the corner of my computer, not in the image coordinates. I’ve worked with these functions and it still doesn’t work
$('body .jcontent').on('click', '.imgpost', function(e){
var imgvalue = $(this).parent();
valueX = e.pageX //- $(imgvalue).offset().left;
valueY = e.pageY //- $(imgvalue).offset().top;
var idimg = this.id;
$('#tagit').css({top:valueY,left:valueX})
$(imgvalue).append('<div id="tagit"><div class="box"></div><div class="name"><input type="text" name="txtname" class="w3-input" id="tagname" placeholder="Comente..." /><input type="button" name="w3-btn" value="Save" id="btnsave" /><input type="button" name="btncancel" value="Cancel" id="btncancel" /></div></div>');
$('#tagname').focus(); //puts the cursor inside text-field
})
try doing your DIV where the image is inserted as position relative, if that doesn’t work it would be nice to have your code in Plunker so we can help solve
– luigibertaco
You’ve already assigned
$(this).parent()
to the variable, then instead of$(imgvalue).append('...');
see ifimgvalue.append('...');
can solve the problem.– Ivan Ferrer