How to modify an image’s attr use jquery? I want set the image's height as the window.height
<script type="text/livescript">
$(document).ready(function(){
var height = $(window).height();
$('img').attr('height',height);
});
</script>
<img src="http://farm7.static.flickr.com/6124/6022097678_4477a09976_o.jpg" />
I think you could use:
JS FIddle demo
Or you could use
prop()in place ofattr():JS Fiddle demo
But both of these are variations on what you’ve already written, the problem you’re having is that you’ve used
type="text/livescript"in yourstyletag, if you amend that to:style="text/javascript"it works.References:
attr().prop().height().