Reputation: 1070
i'm trying to change the title attribute of a div when clicking on a link but it's not working here's the code
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$("a#change").click(function() {
$("#city").attr("title", "new title");
});
});
</script>
and the body :
<a href="#" id="change">change</a>
<div id="city" title=""></div>
Upvotes: 0
Views: 369
Reputation: 10040
$(document).ready(function(e) {
$("a#change").click(function(e) {
e.preventDefault();
$("#city").attr("title", "new title");
});
});
If you want to change any property of element, you can use .attr()
or .prop()
. But here i used .attr()
.
For More Examples See Documentation:
Upvotes: 3
Reputation: 704
try one of the following lines of code:
// this will change the content of the div itself
$("#city").html("new title");
// this will change the title attribute's value
$("#city").attr("title", "new title");
Upvotes: 1