0

Yesterday I have put the question which was answered correctly but now I want to convert that same code into javascript. I have made some changes but its not work

working code- http://jsfiddle.net/SXzyR/8/

mycode- http://jsfiddle.net/SXzyR/11/

2
  • 1
    This type of question, where you're looking to refactor working code, should be posted on codereview.stackexchange.com Commented Oct 18, 2012 at 7:57
  • jQuery is JavaScript... but I take it you're trying to ditch jQuery Commented Oct 18, 2012 at 7:58

2 Answers 2

1

You want to use this.id instead of document.getElementById(this) to get the id string where this is a DOM element.

Sign up to request clarification or add additional context in comments.

2 Comments

why document.getElementById(this) not working
@amit, because this references the element, not the id of the element
1

Please read some tutorials about jQuery. This is a good start, also have a look here.

jQuery isn't another language, it's a library for JavaScript. Considering the following line from your "translated" code:

txtval(document.getElementById(this)

Instead of writing document.getElementById you can simply use jQuery to write

txtval($(this))

as in the first example (working code).

Also you are mixing jQuery with "native" JavaScript/DOM functions in your code. Don't reinvent the wheel, use jQuery to accomplish your task.

2 Comments

tried but not working txtval(document.getElementById(this)
@amit try document.getElementById(this.id) or document.getElementById($(this).attr('id')) to pass the id, not the DOM element...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.