symbolen.parent = object;
object.element.onclick = function() {
this.parent.position.x = 0;
this.parent.position.y = 0;
this.parent.position.z = 0;
this.parent.scale.x = 4,
this.parent.scale.y = 4;
};
i want to convert the javascript code to jquery. Because i want to use "siblings". how can i change it ? is there any website for that?
for example i tried this code with scale first , there is no error message, but it is not working...
$('object').click(function(event) {
$(this).parent().css('scale', '4');
$(this).parent().siblings().css('scale', '0');
event.preventDefault();
});
symbolen.parent = object;
object.element.onclick = function() {
this.parent.position.x = 0;
this.parent.position.y = 0;
this.parent.position.z = 0;
this.parent.scale.x = 4,
this.parent.scale.y = 4;
};
i want to convert the javascript code to jquery. Because i want to use "siblings". how can i change it ? is there any website for that?
for example i tried this code with scale first , there is no error message, but it is not working...
$('object').click(function(event) {
$(this).parent().css('scale', '4');
$(this).parent().siblings().css('scale', '0');
event.preventDefault();
});
Share
Improve this question
edited Oct 18, 2018 at 9:12
Mark Baijens
13.3k11 gold badges50 silver badges76 bronze badges
asked Oct 18, 2018 at 8:32
JunJun
411 gold badge2 silver badges10 bronze badges
1
- 3 @Cid but javascript is not jQuery. – Mark Baijens Commented Oct 18, 2018 at 8:46
1 Answer
Reset to default 1You can wrap element(s) in a jQuery object with $(element)
. Then you can do any jQuery functionality with it. I changed 'object'
selector into object.element
. You don't use quotes here because you use the element in the variable directly instead of using a selector. Also scale
is not a css attribute so i assume you mean transform: scale()
//Mimic your object.element
var object = {};
object.element = document.getElementsByClassName('scale');
//Add on click handler and set scale on click.
$(object.element).click(function() {
$(this).css("transform", "scale(4, 4)");
$(this).siblings().css("transform", "scale(1)");
});
div#parent {
text-align: center;
}
div#scale {
width: 100px;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="parent">
<br>
<div class="scale">Scale on click</div>
<br>
<br>
<br>
<div class="scale">Scale on click</div>
<br>
</div>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745313382a4622103.html
评论列表(0条)