Somk Somk - 1 year ago 74
CSS Question

jQuery data() returns undefined constantly

Below is the HTML and following jQuery. If I return the attr("data-conn"); it alerts the correct value but using .data("conn") it doesn't. Why?

<!-- ... -->
<a href="link.html" class="textbutton" data-conn="text3">
<img src="/images/image.png">
<span style="width:610px;height:200px;float:right; background-color:#bcbcbc;font-size:15px;line-height:15px;">
<div class="texts" id="text1">Initial Header</div>
<span class="texts" id="text2" style="display:none;">Text for another one</span>
<span class="texts" id="text3" style="display:none;">Content Text</span>

<script type="text/javascript">
var link = $(this).data("conn");
$(".texts").fadeOut(1000, function() {
return false;

Answer Source

the way your trying works fine

var link = $(this).data("conn");

use latest version jquery . Here is a working demo

you may alternatively try like this

var link = $(this).attr("data-conn");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download