Как передать элемент jquery в конструктор объекта?
Подскажите пожалуйста, как передать значение ширины дива по айди в объект, делаю так
jtable = {
width: $('#table').width(),
а потом alert(jtable.width);показывает значение Null когда так
alert($('#table').width())
То все ок. :cray: |
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<div>div</div>
<script>
jQuery(function ($) {
var obj = {};
obj.width = $('div').width();
alert($('div').width() + '; ' + obj.width);
});
</script>
|
Спасибо большое, а как теперь еще присвоить метод этому объекту?
jQuery(function($){
jtable = {
PositionX: 25
width: $('#table').width()
draw: function(){
$('#table').css('top', this.PositionX);
}
});
мне нужно что бы менялась позиция дива по высоте, но теперь такая ошибка Uncaught SyntaxError: Unexpected identifier |
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<div style="position: absolute; border: solid 1px">div</div>
<script>
jQuery(function ($) {
var obj = {
PositionX: 25,
width: $('div').width(),
draw: function(){
$('div').css('top', this.PositionX);
alert($('div').css('top'))
}
};
alert(obj.width);
obj.draw();
});
</script>
|
а я скобочку фигурную пропустил :cray:
спасибо большое, ты вообще отец жаваскрипта! :victory: |
Цитата:
|
| Часовой пояс GMT +3, время: 04:35. |