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
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I need get a value using jquery "data()". but I need to do it by doing something like this. So please give me an idea . Thank you in advance.
//html
<div id="myid" data-cityid="Colombo" ></div>
var name = "cityid";
$("#myid").data(""+name+""); // this way not working :(
Your are trying to get attribute, use attr() for it with complete name of attribute:
var name = "data-cityid";
alert($("#myid").attr(name));
Here is demo
You try to use attr():
To get:
$("#myid").attr('data-cityid');
To set:
$("#myid").attr('data-cityid', name);
Try with attr.
$("#myid").attr("data-"+name);
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');
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Example is in the header
I've been trying to do something like the header of this portfolio for a while. Where you can get different remarks on the same line by clicking the arrow. It also doesn't refresh anything which is neat. I just dont know to how phrase the question. I finally found this example. Can anyone help me with the JS or jQuery code? Sorry if this has been answered before I've tried phrasing it so many different ways but can't seem to find the answer.
Easy mode! Here's a working demo on jsfiddle
Setup some html
<p>
I'm a <span id="remark">Panda</span> bear.
<button id="nextRemark">refresh</button>
<img src="http://i.imgur.com/cFadsAE.gif" id="spinner"/>
<p>
Write some JavaScript (with jQuery)
$(function(){
var remarks = ["Koala", "Kangaroo", "Circus", "Grizzly"],
spinner = $("#spinner"),
delay = 1000;
$("#nextRemark").click(function(event) {
var button = $(this);
// display spinner, hide button
spinner.show();
button.hide();
setTimeout(function() {
var r;
// display remark
if (r = remarks.pop()) {
$("#remark").text(r);
}
// no more remarks
else {
$("#remark").text("dead");
button.remove();
}
// hide spinner, show button
spinner.hide();
button.show();
}, delay);
event.preventDefault();
});
});
It doesn't have fancy animations or superfluous delays, but that's the gist of it.
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.
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/