- Joined
- Dec 14, 2021
- Messages
- 28
- Reaction score
- 2
Well, you see here, I found this code for a div select (http://jsfiddle.net/VRjfm/):
HTML:
CSS:
JavaScript: (This is using jQuery)
But I have a problem with it, it doesn't work with images, also I would like it to be in plain JavaScript, as I don't know anything about how to work jQuery. In fact, I did this:
HTML:
CSS:
JavaScript: (This is using jQuery)
With the code, will the images did show up when you click the div, but when you click one of the images, it doesn't show the image in the selected area, and I would like it to do so. I should mention that I would like to be able to use this in a text editor, so I would need to know which of the options is actually selected. Obviously, the images are just placeholder images, so I am obviously not going to be using the images that I have stated in the JS code above.
HTML:
HTML:
<div class="categories">
<div class="category">1</div>
<div class="category">2</div>
<div class="category">3</div>
</div>
CSS:
.categories{width:150px; height:20px; border:solid 1px green; background:#e1e1e1;}
.category{display:none;}
JavaScript:
$('.categories').prepend('<span>select options</span>');
$('.categories').click(function(){
$('div',this).slideToggle();
$('.categories span').html('select options');
});
$('.category').click(function(e){
e.stopPropagation();
$('.category').slideToggle();
$('.categories span').html($(this).text());
});
But I have a problem with it, it doesn't work with images, also I would like it to be in plain JavaScript, as I don't know anything about how to work jQuery. In fact, I did this:
HTML:
HTML:
<div class="categories">
<div class="category"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQnSG2sk6peNhSUfnsu7W7bHAsNlThy3zd1unYiGpKp_93C2kHQGjSbmYZmL84BTpDWanc:https://image.shutterstock.com/image-vector/ui-image-placeholder-wireframes-apps-260nw-1037719204.jpg&usqp=CAU" alt="placeholder 1"></div>
<div class="category"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRFKwpAYLdgVvhphi1bbppMkQhSmYHBJ2OtpRAVqVuocx5qoXzuHcNjGWHjXBRGJR9uoHM:https://socialistmodernism.com/wp-content/uploads/2017/07/placeholder-image.png%3Fw%3D640&usqp=CAU" alt="placeholder 2"></div>
<div class="category"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRQvNJYG5M1LCfNbTvM6frlwIzRrVM9Vayyk3g-0gXze8EEwGtaFvldLi-QFBSY4kABxlY:https://media.istockphoto.com/vectors/thumbnail-image-vector-graphic-vector-id1147544807%3Fk%3D20%26m%3D1147544807%26s%3D612x612%26w%3D0%26h%3DpBhz1dkwsCMq37Udtp9sfxbjaMl27JUapoyYpQm0anc%3D&usqp=CAU" alt="placeholder 3"></div>
</div>
CSS:
.categories{width:150px; height:20px; border:solid 1px green; background:#e1e1e1;}
.category{display:none;}
JavaScript:
$('.categories').prepend('<span>select options</span>');
$('.categories').click(function(){
$('div',this).slideToggle();
$('.categories span').html('select options');
});
$('.category').click(function(e){
e.stopPropagation();
$('.category').slideToggle();
$('.categories span').html($(this).text());
});
With the code, will the images did show up when you click the div, but when you click one of the images, it doesn't show the image in the selected area, and I would like it to do so. I should mention that I would like to be able to use this in a text editor, so I would need to know which of the options is actually selected. Obviously, the images are just placeholder images, so I am obviously not going to be using the images that I have stated in the JS code above.