Ashutosh Dubey
Ashutosh Dubey

Reputation: 31

How could i access the id of element on whose class emojionearea is being append

I am using emojionearea in my input type based on class name. For submitting the data with AJAX I need to send the id of the input type. When I tried to use $(this).attr('id'); to get the id it says undefined.

Please explain how can access the id with help of $(this), because there are more than 1 fields and the id is being generated dynamically .

I have also tried to access the id with $(this).prev().attr('id');, $(this).parent().attr('id'); etc.

Thanks in advance

$(".emojionearea").emojioneArea({
  pickerPosition: "right",
  tonesStyle: "bullet",
  hidePickerOnBlur: true,
  events: {
    keyup: function(editor, event) {
      this.hidePicker()
      if (event.which == 13) {
        var reciver_id = id;
        var message = editor.html();

        if (message != '' || message != 'undefined') {
          request = $.ajax({
            url: "/send-message",
            type: "POST",
            'async': false,
            data: {
              'message': message,
              'reciver_id': reciver_id,
              '_token': CSRF_TOKEN
            },
          });

          request.done(function(res) {
            if (res) {
              editor.html('');
              var text = 'text';
              // ths.parent().parent().children().find('.chat-scroll').append(element);
              $(this).find('.classname').append(text);
            }
          });

          request.fail(function(jqXHR, textStatus) {
            console.log("Request failed: " + textStatus);
          });
        }
      }
    }
  }
});

Upvotes: 0

Views: 269

Answers (0)

Related Questions