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'm attempting to associate a data value with a div created dynamically, however I have not been able to get this to work. I've tried looking around online but can't seem to adapt any examples to fit my problem. If anyone could help I would be very appreciative. The error I'm getting says that:
.data is not a function
If I try putting the $ operator in front control just passes right through my block of code and nothing happens.
var container = $("#container");
('<div class="orb"></div>').data(num).appendTo(container);
It works well:
var $container = $('#container');
$('<div class="orb"></div>').data('num', 123).appendTo($container);
console.log($('.orb').data('num'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="container"></div>
What is your problem?
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
So I have this function:
var test = $('#currentCat').closest('div');
alert(test);
And here is the HTML
<div class="collapse" id="26">
Hoodies (6)
</div>
But instead of giving me HTMLDivElement I get Object and it's not working
var test = $('#currentCat').closest('div');
jQuery does not return DOM elements. It returns a jQuery object, which is also an array, which CONTAINS DOM elements.
Do this:
var $list = $('#currentCat').closest('div');
var element=$list[0]; // Get first item from the array
console.log(element);
Pro debugging hint:
Next time you have a question like this, examine the contents you're looking at.
Had you done a console.log(test), you could have seen it was an array (or array-like) structure.
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 div which outerwidth () returns the selector itself in an array
For $('.slidePopup').outerWidth() its returning like this
<div class="slidePopup">
......
<div class="sildeInside"> </div>
</div>
Has someone else faced the same issue?
It seems this is an existing bug and fixed in older version.
https://bugs.jquery.com/ticket/12491
Please check whether you are using latest version of jQuery. If not consider upgrading to latest version of jQuery or pass "false" as argument as mentioned in the link
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
below i have my fiddle which i want to change the text color when the radio button is selected. However i cant get it to work. at the moment it isnt firing at all and i cant get the div css to change.
$(".package-container").click(function () {
$(this).closest('.radio-group-row').find('.package-title').removeClass('highlight');
$(this).find('input:radio').prop('checked', true);
$(this).find('.package-title').addClass('highlight');
});
http://jsfiddle.net/46jGT/3/
EDIT
Thanks, it does work with the JSFiddle, but in my .net project i cant get this peice to work. i have jquery 1.9 referenced at the bottom on the master page with this code on the control page.
As mentioned in comments, you're missing the jquery library. Your code is working fine as it is once the library is added
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 9 years ago.
Improve this question
I'm trying to change the body content when I resize the windows, but after 2 hours searching and trying, I get nothing.
This is my last jQuery code:
$(window).resize(function(){
if($(window).width<=320){
changeHTML();
}
});
var changeHTML=function(){
alert("wow");
//$('body').load('../index2.html');
}
The "index2.html" is something like this:
<div>
A lot of stuff
</div>
$(window).width is incorrect, as width() is a method. Use $(window).width() instead.
See working jsFiddle 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 3 years ago.
Improve this question
I am trying to manipulate elements outside of iframe by setting JS inside of my iframe
The style.backgroundColor code works but not innerHtml
I have
<script type="text/javascript">
//get main document element.
var ititle= parent.document.getElementById('MainTitle');
//works
ititle.style.backgroundColor = "#FFCC00";
//doesn't work
ititle.innerHtml='test html';
</script>
The above script is inside my iframe
Are there any reasons why? Thanks a lot.
Because JavaScript is CaseSensitive, and it's innerHTML (all uppers):
ititle.innerHtml='test html';
//should be
ititle.innerHTML='test html';