I am learning jQuery by implementing its properties. I am having difficulties when I'm trying to make a div stick to the top of the page when its scrolled to. This is my HTML div:
<div class="col span_1_of_2 poll_div" id="poll-div">
<p>POLL OF THE WEEK</p>
<p>Best pakistani singer?</p>
<table>
<tr>
<td width="100%">
<input type="submit" id="op1" onclick="load(this.id);" class="options option1" value="option # 1"/>
</td>
<td class="numb">
<div id="votes1"><?php $conn = mysql_connect('localhost', 'root', '');
mysql_select_db('poll');
$row= mysql_fetch_assoc(mysql_query("SELECT * FROM `polls` WHERE 1"));
echo $row['option1'] . "/" . $row['total'] ?></div>
</td>
</tr>
<tr>
<td width="100%">
<input type="submit" id="op2" onclick="load(this.id);" class="options option2" value="option # 1"/>
</td>
<td class="numb">
<div id="votes2"><?php echo $row['option2'] . "/" . $row['total'] ?></div>
</td>
</tr>
<tr>
<td width="100%">
<input type="submit" id="op3" onclick="load(this.id);" class="options option3" value="option # 1"/>
</td>
<td class="numb">
<div id="votes3"><?php echo $row['option3'] . "/" . $row['total'] ?></div>
</td>
</tr>
</table>
</div> <!--Poll-->
EDIT CSS:
background-color: white;
position: fixed;
width: 25%;
float: right;
margin-right: 2%;
margin-top: 3.5%;
border: 1px solid #ccc;
box-shadow: 2px 2px 2px 2px #ccc;
padding-bottom: 30px;
and finally JQuery:
$(document).ready(function(){
$(window).scroll(function(){
if($(this).scrollTop() > 280 && $("#poll_div").css('position') == 'relative'){
$("#poll_div").css("position", "fixed");
}
if($(this).scrollTop() < 400 && $("#poll_div").css('position') == 'fixed'){
$("#poll_div").css({'position': 'static'});
}
});
});
If I place the line window.alert("Hello"); instead of the css property change in JQuery, it works fine but not this css property line.