this question has answer here:
- jquery name value of hidden field 1 answer
i have little of issue writing script.
$(function(){ $(".wolny").click(function() { var godzina = this.id; var minuta = this.name; alert(godzina + ":" + minuta);
});
alert should give me output looking hour:minute. instead of getting this: hour:undefined. dont know :x
here's html code (php generated)
<div class="col-sm-3 kafelek wolny" name="15" id="9"></div>
thank's help.
try using .attr()
function instead so:
var minuta = $(this).attr('name');
this works because name
in case attribute , not property. work random attribute foo
may add.
a better way add data attribute data-name="something"
, read $(this).data(name)
.
working example:
$(function(){ $(".wolny").click(function() { var godzina = this.id; var minuta = $(this).attr('name'); alert(godzina + ":" + minuta); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="col-sm-3 kafelek wolny" name="15" id="9"> click me! </div>
Comments
Post a Comment