Rich-text Reply

Insert a button an replicate that in every product

sebasoffia 10-29-14

Insert a button an replicate that in every product

Hi Guys,

I want to insert a button in every product of this:
https://www.daybreakhotels.com/it-IT/day-use-lusso/day-use-break-hotels-roma

 

My question is: how can I replicated this in every product. In this case the products are those that have the price in red.

Thanks guys.

Opsessed 10-29-14
 

Re: Insert a button an replicate that in every product

Hi.. I'm new on this forum so I'm not sure if this is what you're looking for, but the jQuery to select all of these would be:

$('.ulBtn .pointer a');

So if you wanted to append something - like a button everwhere - you could use something like this:

$('.ulBtn .pointer a').append("<button>Yo</button>");

Does this help?
Level 2
sebasoffia 10-31-14
 

Re: Insert a button an replicate that in every product

Sorry but my knowledge in Jquery is limitated, but, this is the code that is create for every button:

$(".result > li:eq(0) > ul:eq(0) > li:eq(0) > a:eq(0)").append("<div id=\"optimizely_879889738\">...</div>");
$("#optimizely_879889738").replaceWith("<div id=\"optimizely_879889738\"></div>\n<div class=\"buttonBookOnRequest\" style=\"padding-top:20px\">\n<button type=\"submit\" class=\"brown\" onclick=\"ga('send', 'event' , 'Prenotazione' , 'clic' , 'Prenota' );\">Prenota</button>\n</div></div>");
$(".result > li:eq(0) > ul:eq(0) > li:eq(0) > a:eq(0) > font:eq(0)").css({"width":"84%"});
$(".result > li:eq(0) > ul:eq(0) > li:eq(0) > a:eq(0) > span:eq(0)").css({"padding-left":"4px", "padding-right":"4px", "margin-left":"0px", "margin-right":"8px"});
$(".result > li:eq(0) > ul:eq(0) > li:eq(0) > a:eq(0) > div:eq(2)").css({"padding-top":"25px"});
$(".result > li:eq(0) > ul:eq(0) > li:eq(0) > a:eq(0)").css({"min-height":"60px"});

How can I implement the solution that you are giving me in this case?

One thing that you need to know that are more than 1200 hundreds products, just in this page where this must be replicated.

What I want to do is creating a variable that could be replicated, but when I create a button, this appear with a unique ID, for example:id=\"optimizely_879889738\".

Did you know how could be done this?

Thanks @Opsessed
adzeds 10-31-14
 

Re: Insert a button an replicate that in every product

Hi,

What are you looking to insert?

Are you trying to add a new button to each product?

If so then you need to look into looping through your elements on the page and inserting your code whenever you get a match on a product.

If you let me know what you want to add I will send over some example code.
David Shaw
Level 11
sebasoffia 11-03-14
 

Re: Insert a button an replicate that in every product

Thanks for your response @adzeds 

 

My question is how can I recognize a "loop", sorry I'm not very good with code.

If you see the example behind your response you will see how is made my code.

 

Thanks in advanced for your respose.

 

Regards!

Opsessed 11-03-14
 

Re: Insert a button an replicate that in every product

[ Edited ]

This might work if you are trying to loop:

var i = 0;

$('.ulBtn .pointer a').each(function(){

$(this).append('<button id='+i+'>Yo</button>');

i = i+1;

});

The .each() part loops and the incrementing variable "i" gives each button a unique ID. This is only one of a few ways to do this, but I think this is the most readable Smiley Happy

Hope it helps!

Level 2
Opsessed 11-04-14
 

Re: Insert a button an replicate that in every product

Or the more compact way:

$('.ulBtn .pointer a').each(function(i){

$(this).append('<button id='+i+'>Yo</button>');

});

(Does the same)
Level 2