jQuery.makeArray( obj )
Turns anything into a true array.
Typically it will be unnecessary to use this function if you are using jQuery which uses this function internally.
For example,we are block having a list of articles(dynamically from backend) with same class and different ids.And we want to insert some ads or text(ads or text doesn't get repeated), the we can try this method.
<html>
<head>
<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(
function()
{
$('.one').map(function(){(this.id)});
}
);
//Grouping into array and selecting the particular array and appending the text or any tags
$(document).ready(function(){
var arr = jQuery.makeArray($('.one'));
$("#"+(arr[0].id)).append('<a href="http://clickserve.cc-dt.com/link/tplclick?lid=41000000026959866&pubid=21000000000164813"><img src="http://clickserve.cc-dt.com/link/tplimage?lid=41000000026959866&pubid=21000000000164813" border=0 alt=""></a>')
$("#"+(arr[1].id)).append('<a href="http://clickserve.cc-dt.com/link/tplclick?lid=41000000026959859&pubid=21000000000164813"><img src="http://clickserve.cc-dt.com/link/tplimage?lid=41000000026959859&pubid=21000000000164813" border=0 alt=""></a>')
$("#"+(arr[2].id)).append('<a href="http://clickserve.cc-dt.com/link/tplclick?lid=41000000026959856&pubid=21000000000164813"><img src="http://clickserve.cc-dt.com/link/tplimage?lid=41000000026959856&pubid=21000000000164813" border=0 alt=""></a>')
});
</script>
</head>
<body>
<div id="wrapper">
<div class="one" id="1">
Article 1
</div>
<div class="one" id="2">
Article 2
</div>
<div class="one" id="3">
Article 3
</div>
</div>
</body>
</html>
Browser Output<head>
<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(
function()
{
$('.one').map(function(){(this.id)});
}
);
//Grouping into array and selecting the particular array and appending the text or any tags
$(document).ready(function(){
var arr = jQuery.makeArray($('.one'));
$("#"+(arr[0].id)).append('<a href="http://clickserve.cc-dt.com/link/tplclick?lid=41000000026959866&pubid=21000000000164813"><img src="http://clickserve.cc-dt.com/link/tplimage?lid=41000000026959866&pubid=21000000000164813" border=0 alt=""></a>')
$("#"+(arr[1].id)).append('<a href="http://clickserve.cc-dt.com/link/tplclick?lid=41000000026959859&pubid=21000000000164813"><img src="http://clickserve.cc-dt.com/link/tplimage?lid=41000000026959859&pubid=21000000000164813" border=0 alt=""></a>')
$("#"+(arr[2].id)).append('<a href="http://clickserve.cc-dt.com/link/tplclick?lid=41000000026959856&pubid=21000000000164813"><img src="http://clickserve.cc-dt.com/link/tplimage?lid=41000000026959856&pubid=21000000000164813" border=0 alt=""></a>')
});
</script>
</head>
<body>
<div id="wrapper">
<div class="one" id="1">
Article 1
</div>
<div class="one" id="2">
Article 2
</div>
<div class="one" id="3">
Article 3
</div>
</div>
</body>
</html>
By using jQuery.makeArray we can print the datas inside the block.For reference please check this http://old.nabble.com/jquery-array-td23232285s27240.html
No comments :
Post a Comment