+ 13

javascript and jquery mixed in one line

can pure javascript and Jquery be mixedin one line (with just 1 semicolon) example: get Element and set it with innerHTML not html $("#firstelement").innerHTML="hi"; or make element and set it's style with .style.prop, Not .css({"":""}); var b= $("#element1"); var c= $("<div></div>"); c.attr("id","idSecond"); c.append(b); $("#idSecond").style.width= "200px"; Look at the last line - second code, is that possible? Thanks for your time

11th Jan 2017, 11:38 PM
Immanuel
Immanuel - avatar
1 Answer
+ 5
You can not mix JS and jQuery like this: $("#firstelement").innerHTML="hi"; but, you can add [0] and it will works: $("#firstelement")[0].innerHTML="hi"; $("#idSecond")[0].style.width= "200px"; or use jQuery methods: $("#firstelement").html("hi"); $("#idSecond").css('width', "200px");
11th Jan 2017, 11:48 PM
Vladimir Honcharenko
Vladimir Honcharenko - avatar