Код: Выделить всё
[list]
[*]
[url=/2]1[/url]
[*]
[url=/3]2[/url]
[/list]
Как лучше всего добраться до него с помощью jQuery?
Я пробовал:
Код: Выделить всё
console.log($('#blogPagination div ul > li a ').attr("href"));Код: Выделить всё
console.log($('#blogPagination > a ').attr("href"));Код: Выделить всё
$('#blogPagination').children('a') Код: Выделить всё
console.log($('#blogPagination div ul li a').attr("href"));Спасибо
РЕДАКТИРОВАТЬ:
После ответа Нбрукса вот что я пробовал:
Код: Выделить всё
function bindPagination() {
console.log("bind");
$(function() {
var links = $("#blogPagination ul a").map(function(e) {
e.preventDefault();
return this.href;
}).get();
console.log(links);
});
Учитывая ответ Сифаро, я тоже пробовал:
Код: Выделить всё
$('#blogPagination').find('a').each(function(e) {
e.preventDefault();
console.log($(this).attr('href'));
});
РЕДАКТИРОВАТЬ 3:
Я хотел бы дать более подробную информацию об этой функции, которая может оказать существенное влияние после все:
чтобы загрузить эту нумерацию страниц, я использую Ajax и руль, завернутый в функцию готовности документа:
Код: Выделить всё
$(document).ready(function(){
// Get the customer service stats
var Content = {
init: function() {
/* this.getHomePosts(); */
this.getBlogPosts();
},
getBlogPosts: function(offset) {
if(offset == undefined){
offset = 0;
}
// GET the events with JSON
$.ajax({
type: "POST",
data: {},
url: site_url+"/main/blog/"+offset,
dataType: "json",
success: function(results) {
posts = results["posts"].map(function (blogContent) {
if( blogContent.picture != '' ) {
return {
Title: blogContent.title ,
Picture: Content.urlPostPic + blogContent.picture ,
Video: '' ,
Text: blogContent.text ,
Datetime: blogContent.datetime ,
}
} else {
return {
Title: blogContent.title ,
Picture: '' ,
Video: blogContent.video ,
Text: blogContent.text ,
Datetime: blogContent.datetime ,
}
}
});
pagination = {pagination: results["pagination"]};
var template = Handlebars.compile( $('#templateBlog').html() );
$('#blogPosts').append( template(posts) );
var template = Handlebars.compile( $('#templatePagi').html() );
$('#blogPagination').append( template(pagination) );
// Here we call bindPagination
Подробнее здесь: [url]https://stackoverflow.com/questions/18175442/how-to-get-all-the-links-of-a-list-inside-a-div[/url]
Мобильная версия