Selecting class inside div in jquery [closed] - javascript

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 select a class inside div.
my code:
<div id="cool" style="width: 80%;height: 80%;margin: auto;">
cool
</div>
Selector:
$('#cool .redirect').attr('href', google.com);
it does not work. Please suggest.
I'm a beginner and just started to learn jquery!

Your code works for me once I correct your attempt to use google.com (that is, the value of the field named com in the nonexistent variable google). Put quotation marks around the string and it works fine.

Related

How do i add attribute to html tag with jQuery [closed]

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 have a html page with <html> tag where I want to add dir="rtl" and lang="ar" attributes using jQuery when user click on arabic language in drop-down.
I tried using $(html).attr("dir","rtl")
But it returns undefined. Can somebody help as I'm new to jQuery
There is an error on your code, the "html" tag should be written with quotes as folows:
$('html').attr("dir","rtl")
Ok, the question is closed, answer given, so no use for this answer anymore.

Getting an innerHtml text of a tag doesn't work, but innerText is working [closed]

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 5 years ago.
Improve this question
I'm learning JavaScript and I'm unable to figure out why the below code doesn't return the value inside span tag with id "name".
console.log(document.getElementById('person').innerHtml)
My name is <span id="person">Anon</span>.
incorrect output (returns undefined)
Whereas, replacing innerHtml with innerText works fine.
console.log(document.getElementById('person').innerText)
My name is <span id="person">Anon</span>.
correct output (retuns Anon)
To get the correct result, use .innerHTML with all caps. Sometimes a simple typo can cause your code to become ineffective.

Why is my custom data attribute not working? [closed]

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 5 years ago.
Improve this question
Using jQuery
console.log($(this).html());
console.log($(this).data('section'));
yields
Include Children?
and
undefined
and I'm not sure what I'm doing incorrectly. The <a> here is inside an un-ordered list <li> tag, but I'm not sure why that should matter. Thanks in advance!
As you said it is <li> enclosing the <a>
then it should be:-
console.log($('li a').html());
console.log($('li a').data('section'));
Example:-
console.log($('li a').html());
console.log($('li a').data('section'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li>Include Children?</li>
Note:- you can do $(this).find('a').data('section'); also based on your HTML structure.

JavaScript innerHTML change onclick not working [closed]

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 want to change a piece of text with the click of a button, this doesn't work. Any ideas?
<div>
This text should stay, <span id="x">This text should change.</span>
</div>
<button type="button" onclick='change()'>Change</button>
<script type="javascript/text">
function change() {
document.getElementById('x').innerHTML='The text has changed.';
}
</script>
What did I do wrong?
Your type attribute is wrong. You don't really need it at all. If you do want to include it, change it to text/javascript.

Multiple conditions in JavaScript [closed]

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 have created the javascript based demonstration and now I want to hide an image on click in certain condition only.
$("#clear").click(function(){
if ($('#image').is(":visible") && ('#image2').is("hidden")) {
$("#image").hide();
};
});
As you can see my code is not right, so I want to know how to format my code properly. I couldn't find the right way to write multiple conditions in one string. Thanks in advance.
The problem is that you forget to add $ (jQuery) to your second condition and selector hidden is incorrect, should be :hidden:
if ($('#image').is(":visible") && $('#image2').is(":hidden"))

Categories