Convert Javascript code, that changes DOM element's background color, to JQuery -


i new in jquery , still learning. problem don't know how convert following javascript code jquery.

javacript:

document.getelementsbyclassname('p-bg')[0].style.backgroundcolor = '#'+this.color 

thanks in advance guys.

by way full code:

<input class="color" onchange="document.getelementsbyclassname('p-bg')[0].style.backgroundcolor = '#'+this.color"> 

thanks again

$(".color") jquery class selector

.change .change() form events

.eq() .eq() filter elements

.css() .css() manipulation

$(".color").change(function(){     $(".p-bg").eq(0).css("background-color", $(this).css("color")); }) 

note document.getelementsbyclassname('p-bg')[0] in jquery equivalent $(".p-bg").eq(0)

remember in jquery, dom must loaded start working, eg:

$(document).ready(function(){     //you jquery code here... }) 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -