<a href="javascript:void(0);" detail="<?php echo $id; ?>" title="View" class="view">View</a>
Can access this via :
document.getElementById('view').getAttribute("detail");
OR
$(this).attr('detail');
Example:
<html>
<head>
<title>Custom Attribute</title>
</head>
<body>
<a href="javascript:void(0);" detail="1" title="Click to alert this id." class="view">Alert this id</a><br /><br />
<a href="javascript:void(0);" detail="2" title="Click to alert this id." class="view">Alert this id</a><br /><br />
<a href="javascript:void(0);" detail="3" title="Click to alert this id." class="view">Alert this id</a><br /><br />
<a href="javascript:void(0);" detail="4" title="Click to alert this id." class="view">Alert this id</a><br />
</body>
</html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$('document').ready(function(){
$('.view').click(function(){
alert($(this).attr('detail'));
})
})
</script>
Can access this via :
document.getElementById('view').getAttribute("detail");
OR
$(this).attr('detail');
Example:
<html>
<head>
<title>Custom Attribute</title>
</head>
<body>
<a href="javascript:void(0);" detail="1" title="Click to alert this id." class="view">Alert this id</a><br /><br />
<a href="javascript:void(0);" detail="2" title="Click to alert this id." class="view">Alert this id</a><br /><br />
<a href="javascript:void(0);" detail="3" title="Click to alert this id." class="view">Alert this id</a><br /><br />
<a href="javascript:void(0);" detail="4" title="Click to alert this id." class="view">Alert this id</a><br />
</body>
</html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$('document').ready(function(){
$('.view').click(function(){
alert($(this).attr('detail'));
})
})
</script>
No comments:
Post a Comment