0

The following code should alert the HTML content of a DIV. The DIV is selected by finding its data attribute for the field panel. However the alert is undefined for reasons I cannot explain.

$('.access .panel').html(results).data('panel','logon');

  alert($('.access .panel[data-panel=logon]').html());
1
  • 1
    I've had troubles using "data" before. Try setting the "attribute" instead. $('.access .panel').html(results).attr('data-panel','logon'); Commented Jan 17, 2015 at 14:48

1 Answer 1

1

Using the data method to set the data for an element doesn't change the data attribute. The data attribute is the initial value, not the current value.

If you set the data attribute, you can find it using the selector:

$('.access .panel').html(results).attr('data-panel','logon');
Sign up to request clarification or add additional context in comments.

1 Comment

@BhojendraSah: That returns the current value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.