Ticket #11712 (closed bug: invalid)
Onfocus inside Jquery append
| Reported by: | anonymous | Owned by: | anonymous |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | manipulation | Version: | 1.7.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
When I was trying to append a textbox inside a div using append method, its stops working when I add javascript onFocus eg: below
$('#examplediv').append('<input type="text" value="email" onFocus="if(this.value=='email')this.value=;" />')
Change History
comment:2 Changed 14 months ago by sindresorhus
- Owner set to anonymous
- Status changed from new to pending
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.
Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.
comment:3 Changed 14 months ago by anonymous
- Status changed from pending to new
i am new to jquery and dont know to write test cases as u asked. So try the solution. hitesh
comment:4 Changed 14 months ago by sindresorhus
- Priority changed from undecided to low
- Resolution set to invalid
- Status changed from new to closed
- Component changed from unfiled to manipulation
That code isn't valid. you need to escape the single quotes in the onFocus attribute. You also should NOT do this. You should rather use even handlers. I suggest you ask a question on the forums, IRC #jquery or StackOverflow.
The bug tracker is for verifiable bugs with jQuery Core itself.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

use the below.
<html> <head> <script type='text/javascript' src='c:/hitesh/jqueryLatest.js'></script>
<script> $(document).ready(function() { var $inputBox=$();
$('#examplediv').append($('input'))
}); </script> </head> <body> <div id='examplediv'></div> <input type="text" value="email" onclick="if(this.value='email') this.value='hitesh';"/>
</body> </html>