Home › Forums › Backend Issues (wp-admin) › Can't get width to change
So right now i have it set up so that the width of #theme-column is set at first in the custom fields. What i want is to when acf loads i want it to check acf for if the new #theme-width exists and then override that width with the new width. This is what i have so far.
//Checks for any theme-width so that it might reflect in theme-column on the page
acf.addAction('load', function(){
$('#theme-width').exists(function(){
//alert ('theme-width exists');
$(this).closest('#theme-column').css( "width", "80%");
var column_width = $(this).closest('#theme-column').css( "width");
alert (column_width);
})
});
This will show that the width has changed but when the page loads it stays at the default width. I don’t know what im doing wrong.
I’m not exactly sure how your code is running as there is no .exists()
function in jQuery.
try something like $('#theme-width').each(function(){
jQuery will not act on non existent elements.
Sorry about that the .exists()
function is a jquery plugin that I regularly use for checking if an element is on page or not. Super Useful.
// Tiny jQuery Plugin
// by Chris Goodchild
$.fn.exists = function(callback) {
var args = [].slice.call(arguments, 1);
if (this.length) {
callback.call(this, args);
}
return this;
};
As for using the .each()
function, extremely smart thing to do. I don’t know why that slipped my mind to check for each instance of the element. Worked like a charm!
Dang it actually that didn’t work exactly as expected. It initially assigns the width as the new width but it doesn’t stick and goes back to whatever the default width is. When i change #theme-column
on load, it goes right back to the default width
The topic ‘Can't get width to change’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.