Get value using data [closed] - javascript

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);

Related

How to read the control id and title inside a span by jquery [closed]

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
I have a input text box inside a span . Can anyone help me how to read the input id
<SPAN class=span1><INPUT id=name class="textobx" title=name value=U maxLength=1 ></SPAN>
How will I read the id and title of the input .
Please help me in finding this.
Thanks
Can you try this,
$(function(){
var id = $('span input').attr('id');
var title= $('span input').attr('title');
});
Also, you need to include jquery library
You need to do like this,
var id=$('span input').attr('id');
var tit=$('span input').attr('title');
Which will retrieve the id and title of input tag inside the span.
FIDDLE DEMO

jquery select by attribute using AND and OR operator part 2 [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 looked the question
him need know $( [myc="blue"] AND ([myid="1"] OR [myid="3"]) )
that last answer is $('[myc="blue"][myid="1"],[myc="blue"][myid="3"]')
now i need use for more condition
like -> $( ([myc="blue"] OR [myc="red"]) AND ([myid="1"] OR [myid="3"]) )
please show me the way T.T
To not have to write down every possible attribute combination, use .filter:
$('[myc="blue"], [myc="red"]').filter('[myid="1"], [myid="3"]');
This selects all elements with a myc attribute with values either "blue" or "red". Then it reduces the set to the elements which also have a myid attribute with values "1" or "3".
If you invest a little of your time and have a look at all the possible selectors, you can figure out the solution for such problems on your own.
Your expression
$( ([myc="blue"] OR [myc="red"]) AND ([myid="1"] OR [myid="3"]) )
can be developed as
$( [myc="blue"] AND [myid="1"]
OR [myc="blue"] AND [myid="3"]
OR [myc="red"] AND [myid="1"]
OR [myc="red"] AND [myid="3"] )
Try this code:
$('[myc="blue"][myid="1"],[myc="blue"][myid="3"],[myc="red"][myid="1"],[myc="red"][myid="3"]')

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

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