Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:53:26+00:00 2026-05-24T09:53:26+00:00

I have the following code: function $(id) { return document.getElementById(id); } var material =

  • 0

I have the following code:

function $(id) {
    return document.getElementById(id);   
}
var material = $("material");
var materialPrices = {"invalid": "from £800.00","1": "£1,200.00","2": "£800.00","3": "£800.00"};
var price = 0;
function update() {
    $(".block").animate( { backgroundColor: '#B5D8EA' }, 500);
    price = materialPrices[material.options[material.selectedIndex].value];
    document.getElementById('pprice').innerHTML = price;    
}
material.onchange = update;

basically in the line $(".block").animate( { backgroundColor: '#B5D8EA' }, 500); returns $(".block") is null when a value is selected from the dropdown select box. I have been told that it is to do with: function $(id) but have no idea how I should modify my code to get it all working, please can anyone help, my js is weak!!!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:53:27+00:00Added an answer on May 24, 2026 at 9:53 am

    .. you have a conflict regarding the $ sign.
    $ is a shortcut for jQuery and you overwrite that shortcut to a different function (document.getElementById). The bad thing is that you use jquery with the $ shortcut even after you’ve redefined it.
    The solution is either to rename your function to something else :

    function getById(id) {
         return document.getElementById(id);   
    }
    var material = getById('material');
    

    either use the full jQuery notation for jQuery objects :

      jQuery(".block").animate( { backgroundColor: '#B5D8EA' }, 500);
    

    My oppinion is that if you use jQuery, you can get an element by id quite easy and you don’y need to add another function that takes care of that. ex :

    document.getElementById(someId) == $('#'+someId).get(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code: function checkAmount() { var PayField = document.getElementById('paymentamount');
I have the following code: $(document).ready(function(){ $(.datepicker).each(function() { $(this).datepicker({ beforeShowDay: function(date){ return [$(this).parent().find(span.days).html(), ]
I have the following Javascript code: function checkIfValid(){ var form = document.createuserform; var valid
I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
I have using the following code for developing tabs. $(document).ready(function() { $('#container-1').tabs(); } ....
I have following function in jquery: $('canvas').createWindow('xyz', 500, 600); And js-code behind is: var
I have the following code: <a href=http://mydomain.com/link123 class=someClickEvent>Some Link</a> $(document).ready(function(){ $('.someClickEvent').click(function() { var $deal_id
I have the following code in a function: this.HtmlRef = document.createElement( canvas ); if
I have a following code: $(document).ready(function() { $('a[rel]').each(function() { $(this).qtip( { content: { text:
I have the following code $(document).ready(function(){ // class exists if($('.delete').length) { // add click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.