07-26-2023, 11:27 PM
I'm using a forum software where you can pull up an avatar link using this: {$mybb->user['avatar']}
If no avatar is set then nothing is returned. I want to show an image if no avatar is set.
Currently the HTML is setup like this:
<div id="avatar"><div style="background: url({$mybb->user['avatar']}) center center no-repeat;"></div></div>
The outer div is empty and in the background. This one is the one I'm adding a class too (.defaultavatar) so that a default avatar will display.
The inner div is the one with the avatar displaying. If no avatar is uploaded/selected then it will appear blank.
This is the javascript I'm using:
var myavatar = {$mybb->user['avatar']};
if(typeof(myavatar) = null){
jQuery('#avatar').addClass('defaultavatar');
}
If the avatar URL is empty I want the class defaultavatar to be added to the first div.
How can I do this (get it to work)?
Thanks very much,
Jack Clarke
If no avatar is set then nothing is returned. I want to show an image if no avatar is set.
Currently the HTML is setup like this:
<div id="avatar"><div style="background: url({$mybb->user['avatar']}) center center no-repeat;"></div></div>
The outer div is empty and in the background. This one is the one I'm adding a class too (.defaultavatar) so that a default avatar will display.
The inner div is the one with the avatar displaying. If no avatar is uploaded/selected then it will appear blank.
This is the javascript I'm using:
var myavatar = {$mybb->user['avatar']};
if(typeof(myavatar) = null){
jQuery('#avatar').addClass('defaultavatar');
}
If the avatar URL is empty I want the class defaultavatar to be added to the first div.
How can I do this (get it to work)?
Thanks very much,
Jack Clarke