Jquery Place item dynamically

Is there a way to place element just next to the item.

This is my code . I am setting button item dynamically like this

var button_text = "Learn Now";
$("#ctaBtn").text(button_text);
$("#ctaBtn").css('width', parseFloat(textWidth(button_text) + 30) + "px");

Which is fine but i want the logo which is next to the button adjust its position dynamically. If i change my button text to

var button_text = "Learn More Now !!!";

Then the size of the button increases and logo position is not moved to the right. How can i move the logo dynamically based on the button text size?

Problem courtesy of: user3754380

Solution

Remove the left position from the #Image_logo img and set a right position instead with jQuery. Something like this:

$("#Image_logo img").css("right", $("#ctaBtn").width() + 60);

Instead of 60 you can use any value that is better for you. Now, when you dynamically change the text in the button, the logo moves to the left with it.

Check the code on this jsFiddle .

Solution courtesy of: Alvaro Montoro

我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章