Change background body images with onclick [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm new at javascript and jQuery and I want to use one of those to change my background body images with onclick. Exactly what I want is to create a link with an image so when the people click on it the background body pic will change. Can you help me or give me a simple example.

HTML
<img src="/path/to/image.jpg">Select Image
Javascript
$(document).on('click', 'a.set-background', function(){
$('body').css({
'background' : 'url(' + $(this).find('img').attr('src') + ')'
});
return false;
});

HTML:
<button>Change background</button>
jQuery:
$('button').click(function(){
$('body').css('background-image','image.jpg');
});

Related

Problems with js in wordpress [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a problem with javascript on Wordpress!
I have to insert in my theme this pen https://codepen.io/z-/pen/OBPJKK .
HTML and css work, the only problem to fix is with javascript.
I replaced "$" in the original JS with "jQuery" and I entered this script in Theme Option> Advanced > Code Fields > Space Before head area:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.single .fusion-post-slideshow li img').each(function() {
var caption = jQuery(this).attr('alt');
jQuery(this).after('<span>' + caption + '</span>');
});
});
</script>
The problem lies in the inability to reproduce the onclick effect of the aforementioned pen.
When going to the url of the page http://www.goatsplan.com/goats-magazine/, Wordpress seems not to recognize JS, and it is as if no code has been entered. Please, how can I solve this problem and keep the same type of animation in javascript?
Thank you very much
jQuery(".option").click(function(){
jQuery(".option").removeClass("active");
jQuery(this).addClass("active");
});
Just past the above jQuery in the Footer file/Template
Its working fine--> https://prnt.sc/r04jfi
https://prnt.sc/r04jug

jquery code Inline onlick code for window,open [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am struggling with this for some time and hope to get experts help me.
Context is:
window.open blocked by default (popups blocked)
I was provided with an answer in comment 1 in that question the fiddle is as below
http://jsfiddle.net/chokchai/EgBQK/
This might be the answer but I am failing to understand that:
Can not this be done purely in jQuery? I am talking abt following code:
$('body').append('<div> Share on Facebook </div>');
How can I convert this code to pure jQuery? In the code above, html code is created in jquery code?????
Try this way:
var url = ['http://google.com', 'http://bing.com', 'http://duckduckgo.com/'],
$coll;
$coll = $.map(url, function (val) {
return $('<div/>').append($('<a/>', {
href: '#',
rel: val,
text: 'Share on Facebook'
}).click(handleClick));
});
$('body').append($coll);
function handleClick(e) {
e.preventDefault();
window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(this.rel), 'facebook-share-dialog', 'width=626,height=436');
}
Demo

JQuery: removeAttr does not work properly [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I want to remove an attribute of img. Here you can see my codes :
$("#zoom_05").removeAttr('data - zoom - image');
And my img :
<img id="zoom_05" src="http://localhost:3192/ProductImages/Small/093.jpg" data-zoom-image="http://localhost:3192/ProductImages/Larges/093.jpg" />
I can remove src attribute but I can not remove data-zoom-image attribute. Do you have any suggestion?
You are using whitespaces when you shouldn't:
$(document).ready(function(){
$("#zoom_05").removeAttr('data-zoom-image');
});
In case you don't believe me... :) http://jsfiddle.net/7ZTkC/

How to Set Response In JQuery [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have following jQuery code to submit form data to the server.
$(document).ready(function() {
$("#update").click(function() {
$.post("./Index/StatusUpdateDo",
{
status: $("#status").val()
},
function(data, status) {
setTimeout(quit, 2000);
});
});
Also I have
<div id="response"></div>
in that same page. What i want to do is get server response and print on that 'div'. as I'm new to jquery please help me to do this.
A quick look at the docs would have revealed that .html() assigns HTML content to an element and the front page of jquery.com shows that $('#response') selects an element by ID.
$('#response').html(data);
You put this code in the callback function where you currently call setTimeout.

Unhiding Row using jQuery toggle [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
http://jsfiddle.net/PF8nL/1/
Using the code in the above jsfiddle I am unable to unhide and hide a row using jQuery. According to this stack answer it seems I am doing this correctly.
Do I have some stupid error? possibly causing this?
Code:
$('input[name="custom_rejection_option"]').click(function() {
$('.custom_reject_area').toggle(this.checked);
}};
You had a syntax error
$('input[name="custom_rejection_option"]').click(function () {
$('.custom_reject_area').toggle(this.checked);
});
//You had `}` instead of the closing `)`
You just had some typos and things.
$('input[name=custom_rejection_option]').click(function() {
$('.custom_reject_area').toggle(this.checked);
});
http://jsfiddle.net/PF8nL/5/

Categories

Resources