Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a folder of images; I would like to create a page that lists each of them, and clicking them displays that image as the background.
I have got it working using
<img .... onclick='document.body.style.backgroundImage = url('img/1.jpg')' >
But when I put that into a FOREACH loop it doesn't work.
foreach($phpfiles as $phpfile)
{
echo "<img .... onclick='document.body.style.backgroundImage = url(".$phpfile.")' />";
}
Hope someone can help. Only thing I've found mentioned something about Javascript closures, but I couldn't follow the example it had
You have quotes mismatch. You are prematurely closing your ' single quotes.
Use a proper IDE to code.
Perhaps you forgot to include the path of each image file inside the loop.
foreach($phpfiles as $phpfile)
{
echo "<img .... onclick='document.body.style.backgroundImage = url('img/".$phpfile."')' />";
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to get the element itself through making a function in the div itself I want when someone clicks on the current Element the Element should be deleted by fading in pure JavaScript I have searched on the internet but not getting the answer there are many similar questions on Stack Overflow but none of them giving me the combined answer(Like getting current element through Js in (inline function)).
So anyone can help me
<div style="width: 100px;height: 100px;background:red;" onclick="(function(ele){
console.log('helo')
console.log(ele.currentTarget)})();">
Thanks in advance
This should do it:
I added an id to your div which can be accessed through the getElementById.
<div id='hello' style="width: 100px;height: 100px;background:red;" onclick="
(
function() {
document.getElementById('hello').style.opacity = 0;
document.getElementById('hello').style.transition = '0.5s';
}
)();">
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have a some pictures with values of 1 - 10 E.G. img1.png, img2.png etc.
I also have some code that returns a number. What I would like is to have the returned number append an image.
My code is below and I can't get it to work properly. without the image it returns a normal number, but with it I get a blank return.
$("#ext-row").append("<div class='container returnedInfo'><div class='col-md-2 wordValue'> <img src'/Content/Images/img'" + items[i].WordScore + ".png</div>
Hope this makes sense
Thanks
You have a problem with your markup:
no = next to src
you are closing the src attribute value before appending the image
you never closed the img tag
<img src'/Content/Images/img'" + items[i].WordScore + ".png
The proper code:
$("#ext-row").append("<div class='container returnedInfo'><div class='col-md-2 wordValue'> <img src='/Content/Images/img" + items[i].WordScore + ".png' /></div>");
Also make sure the image path you provide is valid.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to remove loader icon from images after they have been loaded. In order to do that, I need to access $(this) but I cannot access the image element and remove js-image-loading class.
variable html contains dynamic HTML contents fetched via ajax.
$(html).find('img').load(function() {
$(this).removeClass("js-image-loading"); //ok image is done loading, remove icon
});
Is this possible to do?
You forgot to quote to the html selector $(html) should be $('html') but I suggest you to use *:
$('*').find('img').load(function() {
$(this).removeClass("js-image-loading");
});
Or, simply $('img').load()
try
$("html").find('img').load(function () {
$(this).removeClass("js-image-loading"); //ok image is done loading, remove icon
});
OR
$('img').load(function () {
$(this).removeClass("js-image-loading"); //ok image is done loading, remove icon
});
NOTE: html is string not object
DEMO
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I don't know my controller is not working .
I m create a controller but is not working .
I know it's little mistake but i m see many times but now show .
Please Help me .
Angular Code
var myPanelSearch = angular.module('left-panel-search', []);
myPanelSearch.controller=('leftPanelSearch', function($scope){
$scope.msm = "Wincere";
});
HTML Code
<body ng-app="left-panel-search">
<div ng-controller="leftPanelSearch">
{{msm}} {{5+2}}
</div>
<h1>Hello Plunker!</h1>
</body>
Demo
Remove = sign after myPanelSearch.controller, it should be a method invocation, not assignment:
myPanelSearch.controller('leftPanelSearch', function($scope) {
$scope.msm = "Wincere";
});
Also you would have spotted the error if you kept developer console open.
Fixed demo.
Remove the = AFTER controller
.controller()
http://plnkr.co/edit/M8zz7qCu8ZEPn5YMPySX?p=preview
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I've got a button which looks like this:
<a class="buttonS bDefault tipN" id="customerBasket" original-title="<ul class='shoppingBasket'></ul>" href="#"><span class="icos-cart3"></span></a>
Its a tooltip and I want to append list-items to the class shoppingBasket.
I've tried by doing the following:
$('.shoppingBasket ul').append(<li><span class=\'basketPic\'>Test</span><span class=\'basketName\'>Test123</span></li>);
But I get the error:
SyntaxError: Unexpected token '<'
Any ideas what I'm doing wrong here?
You forgot your quotes:
$('ul.shoppingBasket').append("<li><span class='basketPic'>Test</span><span class='basketName'>Test123</span></li>");
EDIT after getting more info:
You're wanting to update an attribute, which is more complicated than just appending something to a dom element. But, you should be able to do it. Try something like this:
$button_title = $('.buttonS').attr('original-title');
$('body').append('<div id="cart-holder" style="display:none;">' + $button_title + '</div>');
$('#cart-holder ul.shoppingBasket').append('<li><span class=\'basketPic\'>Test</span><span class=\'basketName\'>Test123</span></li>');
$('.buttonS').attr('original-title', $('#cart-holder').html());
$('#cart-holder').remove();
This will add a div to the body with the HTML in original-title, append your HTML to it, set the original-title to it, then remove the element it just made. You'll likely have to tweak it to get the effect you want.
Fiddle
Please note that the append() method accepts a string. And you should always add a string to its parameter. Otherwise it won't work for you and you'll get this error.
append("<li><span class='basketPic'>Test</span><span class='basketName'>Test123</span></li>")
This would do it. Otherwise, it won't work.