I
Ivan S
This is probably stupid question (Thomas, you can skip it
), but I
have to ask it ...
I think I don't really understand attributes and properties ... and
their difference, probably because their meaning is very similar (if
not the same) when I translate them on my native language. In some
way, I can understand difference in general, but can someone explain
them to me in the world of HTML & JS ... what is attribute, what is
property and what is(are) their difference(s)?
I've found some online resources, but the explanation is very poor.
I'm asking this because I've read some discussions about Jquery mixing
attributes and properties ... and I found one problem with Jquery.
This is for David Mark's joy and happiness.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<title>Mylib vs Jquery</title>
<script type="text/javascript" src="mylib.js"></script>
<script type="text/javascript" src="jquery-1.4.js"></script>
<script type="text/javascript">
window.onload = function() {
API.setAttribute(API.getEBI("mylibInput"), "type", "text");
$("#jqueryInput").attr("type", "text");
}
</script>
</head>
<body>
<input type="hidden" id="mylibInput">
<input type="hidden" id="jqueryInput">
</body>
</html>
Mylib sets attribute with no problem and input's type is changed to
"text".
On other hand Jquery throws exception:
uncaught exception: type property can't be changed
First of all ... I see that Jquery is mixing properties and attributes
(attr method tries to set property). And it isn't working (correct me
if my code isn't valid in some way). But, I've noticed that input's
~property~ can't be changed, but ~attribute~ can. And that confused
me, because attribute and property are the same in this case.
So, what's the difference between attribute and property?
Thanks for you answers.
Ivan
have to ask it ...
I think I don't really understand attributes and properties ... and
their difference, probably because their meaning is very similar (if
not the same) when I translate them on my native language. In some
way, I can understand difference in general, but can someone explain
them to me in the world of HTML & JS ... what is attribute, what is
property and what is(are) their difference(s)?
I've found some online resources, but the explanation is very poor.
I'm asking this because I've read some discussions about Jquery mixing
attributes and properties ... and I found one problem with Jquery.
This is for David Mark's joy and happiness.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<title>Mylib vs Jquery</title>
<script type="text/javascript" src="mylib.js"></script>
<script type="text/javascript" src="jquery-1.4.js"></script>
<script type="text/javascript">
window.onload = function() {
API.setAttribute(API.getEBI("mylibInput"), "type", "text");
$("#jqueryInput").attr("type", "text");
}
</script>
</head>
<body>
<input type="hidden" id="mylibInput">
<input type="hidden" id="jqueryInput">
</body>
</html>
Mylib sets attribute with no problem and input's type is changed to
"text".
On other hand Jquery throws exception:
uncaught exception: type property can't be changed
First of all ... I see that Jquery is mixing properties and attributes
(attr method tries to set property). And it isn't working (correct me
if my code isn't valid in some way). But, I've noticed that input's
~property~ can't be changed, but ~attribute~ can. And that confused
me, because attribute and property are the same in this case.
So, what's the difference between attribute and property?
Thanks for you answers.
Ivan