SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2010
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is .closest() a javascript or a jQuery object ?

    Up until last week, the event target was a div.no_style_elearning_dropped_multiple_answer but suddenly it is now an img

    So my old if statement no longer works:

    if ($(event.target).is("div.no_style_elearning_dropped_multiple_answer")) {

    I'm trying to replace it with the following if statement:

    var droppedObj = $(event.target).closest("div.no_style_elearning_dropped_multiple_answer")[0];
    if (droppedObj.className.indexOf('no_style_elearning_dropped_multiple_answer') != -1) {

    It works fine but then the droppedObj does not give me access any more to the attribute elearningAnswerId

    The following variable is undefined:

    var elearningAnswerId = droppedObj.attr("elearningAnswerId");

    Note that the element is dynamically added by:

    var droppedContent = "<div class='elearning_question_answer no_style_elearning_dropped_multiple_answer' elearningAnswerId='" + ui.draggable.attr("elearningAnswerId") + "'>" + trim(ui.draggable.html()) + "</div>";

    Is the droppedObj object a javascript object ? Is that why is doesn't have the jQuery attribute ?

    Thanks for any tip.

    Stephane

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2010
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I solved the issue by wrapping the droppedObj in a $(droppedObj) as in:

    var elearningAnswerId = $(droppedObj).attr("elearningAnswerId");

    So as to turn this DOM object into a jQuery object.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •