Is there a way in jQuery to determine whether an element has a value or innerhtml (or both)? For example, if the element is input then it has a val and I can use:
$(this).val();
But if it’s a div then I need to use:
$(this).html();
I need to know whether I have to use val or HTML. My piece of jQuery is:
$(".myclass").each(function(idx){
if (this is a val based element)
use val
else
use html
});
this.tagNamewill tell you which element type you have. jQuery object doesn’t havetagNameproperty.